Write a program to count the number of lines in file.

1 Answer

Answer :

#include<iostream.h>

#include<fstream.h>

#include<conio.h>

void main()

{

ifstream file;

char ch;

int n=0;

clrscr();

file.open("abc.txt");

while(file)

{

file.get(ch);

if(ch=='\n')

n++;

}

cout<<"\n Number of lines in a file are:"<<n;

file.close();

getch();

}


Related questions

Description : Write a program that copies contents of one file into another file.

Last Answer : Assuming input file to be copied file1.txt contents are “Hello Friends…” and file where the contents need to copy is file2.txt already created  #include #include #include #include #include void main() { clrscr(); ifstream fs; ofstream ft; char ch, fname1[20], fname2[20]; cout

Description : Write a program to perform following task (i) Create a text file and store data in it. (ii) Count number of lines and words in that file. 

Last Answer : import java.util.*; import java.io.*; class Model6B { public static void main(String[] args) throws Exception { int lineCount=0, wordCount=0; String line = ""; BufferedReader br1 = new BufferedReader(new ... : " + lineCount);  System.out.println("Number of words is : " + wordCount); } }

Description : What is the function of following UNIX command? WC - lb& (A) It runs the word count program to count the number of lines in its input, a, writing the result to b, as a foreground process. (B) It runs ... (D) It copies the l ' numbers of lines of program from file, a, and stores in file b.

Last Answer : (B) It runs the word count program to count the number of lines in its input, a, writing the result to b, but does it in the background.

Description : Write a program to declare a class ‘book’ containing data members as ‘title’, ‘author-name’, ‘publication’, ‘price’. Accept and display the information for one object using pointer to that object.

Last Answer : #include<iostream.h> #include<conio.h> class book { char author_name[20]; char title[20]; char publication[20]; float price; public: void Accept(); void Display(); }; void ... title \t author_name \t publication \t price\n ; p-> Display(); getch(); }

Description : Write a program to implement the following hierarchy using suitable member functions. Refer Figure No.2.

Last Answer : # include <iostream.h> #include<conio.h> class Student { int roll_no; char name[10]; public: void read_studentData() { cout<< Enter student s roll no and name \n ; cin> ... { result r; clrscr(); r.read_result(); r.display_result(); getch(); }

Description : Write a program to overload the ‘—’ unary operator to negate the values.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> class Number { int x,y; public: Number (int a, int b) { a =x; b =y; } void display() { cout<< ... ; -N1; cout<<"\n After negation:"; N1. display (); getch (); }

Description : Write a program to sort an 1-d array in ascending order.

Last Answer : #include<iostream.h> #include<conio.h> void main() { int arr[20]; int i, j, temp,n; clrscr(); cout<<"\n Enter the array size:"; cin>>n; cout<<"\n Enter ... 0;i<n;i++) {  cout<< \n <<arr[i]; } getch(); }

Description : Write a program to implement single inheritance from the following Refer Figure No.1

Last Answer : #include #include class employee { protected: int emp_id; char name[10]; }; class emp_info:public employee { int basic_salary; public: void getdata() { coutemp_id; coutname; coutbasic_salary; } void putdata() { cout

Description : Write a C++ program to count number of spaces in text file.

Last Answer : Program: #include<iostream.h> #include<conio.h> #include<fstream.h> void main() { ifstream file; int s=0; char ch; clrscr(); file.open("abc.txt"); while ... cout<<"\nNumber of spaces in text file are:"<<s; getch(); }

Description : Write a C++ program to count number of spaces present in contents of file.

Last Answer : #include<iostream.h> #include<fstream.h> #include<conio.h> void main() { ifstream file; charch; int s=0; clrscr(); file.open("abc.txt"); while(file) { ... of spaces present in the content of the given file are:"<<s; getch(); }

Description : Write a program to count number of words from a text file using stream classes.

Last Answer : import java.io.*; public class FileWordCount { public static void main(String are[]) throws IOException { File f1 = new File("input.txt"); int wc=0; FileReader fr = new FileReader (f1); int c=0; try {  while(c ... of words :"+(wc+1)); } finally {  if(fr!=null)  fr.close();  }  } }

Description : Write the applications of object oriented programming.

Last Answer : Applications of object oriented programming are: 1) Real time systems 2) Simulation and modeling 3) Object-oriented databases 4) Hypertext, hypermedia and expertext 5) AI and expert systems ... and parallel programming 7) Decision support and office automation systems 8) CIM/CAM/CAD systems

Description : Write any four benefits of OOP. 

Last Answer : Benefits of OOP: 1. We can eliminate redundant code and extend the use of existing classes. 2. We can build programs from the standard working modules that communicate with one another, ... interface descriptions with external systems much simpler. 10. Software complexity can be easily managed.

Description : Write two properties of static member function

Last Answer : i) A static member function can have access to only other static data members and functions declared in the same class. ii) A static member function can be called using the class name with a scope resolution operator instead of object name as follows: class_name::function_name;

Description : Explain the friend function with proper example.

Last Answer : Friend function: The private members of a class cannot be accessed from outside the class but in some situations two classes may need access of each other s private data. So a common function can be declared which can be made friend ... ; } friend void swap(A,B); }; void swap(A a,B b) { cout

Description : What is parameterized constructor?

Last Answer : A constructor that accepts parameters is called as parameterized constructor. In some applications, it may be necessary to initialize the various data members of different objects with different values when they are ... an argument. Member function put ( ) displays the value of data member m .

Description : What are the rules for virtual function?

Last Answer : Rules for virtual function: 1. The virtual functions must be members of some class. 2. They cannot be static members. 3. They are accessed by using object pointers. 4. A virtual function can ... virtual function is defined in the base class, it need not be necessarily redefined in the derived class.

Description : What is inheritance? Give different types of inheritance.

Last Answer : Inheritance: The mechanism of deriving new class from an old/existing class is called inheritance. OR Inheritance is the process by which objects of one class acquired the properties of ... is a combination of single, multiple, multilevel and hierarchical inheritance. Diagram:

Description : State the rules for writing destructor function.

Last Answer : Rules for writing destructor function are: 1) A destructor is a special member function which should destroy the objects that have been created by constructor. 2) Name of destructor and name of the class should ... should not be classified in any types. 7) A class can have at most one destructor. 

Description : Describe ‘this’ pointer with an example.

Last Answer : this' pointer:  C++ uses a unique keyword called this to represent an object that invokes a member function. This unique pointer is automatically passed to a member function when it is invoked. ... pointer is used to represent object s when setdata ( ) and putdata ( ) functions are called. 

Description : Describe memory allocation for objects.

Last Answer : The memory space for object is allocated when they are declared and not when the class is specified. The member functions are created and placed in memory space only once when they are ... are essential because the member variables will hold different data values for different objects.

Description : Give syntax and use of fclose ( ) function.

Last Answer : Syntax:  int fclose(FILE* stream); Use: This function is used to close a file stream. The data that is buffered but not written is flushed to the OS and all unread buffered data is discarded.

Description : Explain virtual base class with suitable example.

Last Answer : Consider a situation where all three kinds of inheritance, namely, multilevel, multiple, hierarchical inheritance, are involved. This illustrated in fig a. the child has two direct base classes, parent1 & ... Grandparent { }; class Child: public Parent1,public Parent2 { };

Description : Explain use of scope resolution operator.

Last Answer : It is used to uncover a hidden variable. Scope resolution operator allows access to the global version of a variable. The scope resolution operator is used to refer variable of class anywhere in program. ... outside of class. Return_type class_name:: function_name( ) { Function body }

Description : What is multilevel inheritance? Draw the diagram to show multilevel inheritance. using classes with data member and member function. 

Last Answer : When a class is derived from another derived class then it is called as multilevel inheritance.

Description : What is a class? Give its example. 

Last Answer : Class is a user defined data type that combines data and functions together. It is a collection of objects of similar type. Example: class Student { int rollno; char name[10]; public: void getdata( ); void putdata( ); };

Description : State the difference between OOP and POP.

Last Answer : OBJECT ORIENTED PROGRAMMING (OOP) PROCEDURE ORIENTED PROGRAMMING (POP) Focus is on data rather than procedure. Focus is on doing things (procedure). Programs are divided into multiple ... approach is used in C++ language. Procedure oriented approach is used in C language.

Description : Which command is used to count just the number of characters in a file? A. wc - 1 B. wc -c C. wc -w D. wc -r E. None of the above

Last Answer : B. wc -c

Description : You give a 16yr old a #360,000 auto does it count as capital gain and do the kid have to file taxes?

Last Answer : I doubt that a minor can own a car outright, so the parent would be responsible.

Description : Count the occurrence of a string in the nth column of a file using awk -Web-Development

Last Answer : answer:

Description : Which command sends the word count of the file infile to the newfile. A. wc infile >newfile B. wc newfile C. wc infile - newfile D. wc infile | newfile E. None of the above

Last Answer : A. wc infile >newfile

Description : Which is not a size metric? (A) LOC (B) Function count (C) Program length (D) Cyclomatic complexity

Last Answer : (D) Cyclomatic complexity

Description : Write a C++ program to append data from abc.txt to xyz.txt file.

Last Answer : Assuming input file as abc.txt with contents "World" and output file named as xyz.txt with contents "Hello" have been already created. #include #include int main() { fstream f; ifstream fin; fin.open("abc.txt",ios::in); ofstream fout; fout.open("xyz.txt", ios::app); if (!fin)  {  cout

Description : Write a C++ program to write ‘Welcome to poly’ in a file. Then read the data from file and display it on screen.

Last Answer : #include #include #include void main()  { char str[25] = "Welcome to poly",ch; clrscr(); ofstream fout; fout.open("output.txt"); fout

Description : Write a program to copy content of one file to another file.

Last Answer : class fileCopy {  public static void main(String args[]) throws IOException { FileInputStream in= new FileInputStream("input.txt"); FileOutputStream out= new FileOutputStream("output.txt"); int c=0; ... .close();  if(out!=null)  out.close();  }  } }

Description : What does the following command do? grep −vn abc x (A) It will print all of the lines in the file x that match the search string abc (B) It will print all of the lines in file x that do not ... (D) It will print the specific line numbers of the file x in which there is a match for string abc

Last Answer : (A) It will print all of the lines in the file x that match the search string “abc”

Description : Write a note: Count Camillo de Cavour -SST 10th

Last Answer : Count Camillo de Cavour Count Camillo de Cavour, a political leader and an Italian statesman, premier of the Kingdom of Sardinia. He was born at Turin on the August 1, 1810. He was the active ... But unfortunately he died only three months after the declaration of a united Italy on June 6, 1861.

Description : Write a note on Count Camillo de Cavour. -Social Science

Last Answer : Cavour was a realist who practiced realistic politics. He allied with France when necessary and with France's key enemy, Prussia, was necessary. Cavour used international power to achieve his ... neither a revolutionary nor a democrat he played an important role in the unification of Italy.

Description : Describe the procedure of traffic volume count on any road intersection. Also write the method of representation of traffic volume count data.

Last Answer : The procedure of traffic volume count can be done by any of the methods below: a) Manual counting b) Automatic recorders c) Moving car method a) Manual counting: In this method, the ... Volume flow diagrams at intersection iii) Variation charts iv) Traffic flow map v) Traffic trend charts

Description : Is there a unix command to reverse the lines in a file?

Last Answer : answer:tac tac (cat spelled backwards) works like cat, but reverse the order of the lines (last line is written out first).

Description : STL file format is represented by interaction of ______ a.lines and hexagons b.lines and rectangles c.lines and triangles d.lines and circles

Last Answer : c.lines and triangles

Description : STL file converts curved surfaces into_______ a.Polygons b.Lines c.Surfaces d.None of the above

Last Answer : a.Polygons

Description : Python: how to read all the lines of a file in a list -Web-Development

Last Answer : answer:

Description : Which command is used to sort the lines of data in a file in reverse order A. sort B. sh C. st D. sort -r E. None of the above

Last Answer : D. sort -r

Description : Unix command to change the case of first three lines of file “shortlist” from lower to upper (1) $ tr ‘[a-z]’ ‘[A-Z]’ shortlist | head-3 (2) $ head-3 shortlist | tr ‘[a-z]’ ‘[A-Z]’ (3) $ tr head-3 shortlist ‘[A-Z]’ ‘[a-z]’ (4) $ tr shortlist head-3 ‘[a-z]’ ‘[A-Z]’

Last Answer : (2) $ head-3 shortlist | tr ‘[a-z]’ ‘[A-Z]’ 

Description : Ram wants to create a text file to store name and roll number of his students. Suggest, which program he should use. -Technology

Last Answer : He can create a text file using Notepad or WordPad. Follow these steps to create a file using Notepad:(a) Step 1:Click Start.(b) Step 2:Choose All Programs -> Accessories -> Notepad.(c) Step 3: ... dialog box will appear.(g) Step 7:Give file name with extension.(h) Step 8: Click Save button.

Description : Which design metric is used to measure the compactness of the program in terms of lines of code? (A) Consistency (B) Conciseness (C) Efficiency (D) Accuracy

Last Answer : (B) Conciseness