Posts

Showing posts with the label jornal - 5

3.Modify above program to do following operations. (Write new program) 1) Display current contents of the file. 2) Add one more item at the end of file. 3) Again display contents of appended file. 4) Display total no. of objects in the file. 5) Display total no. of bytes in the file. 6) Take item no. from the user, modify the details of that item. 7) Again display contents of modified file. 8) Use proper error handling functions to prevent errors

 /*J_5_P_3 Modify above program to do following operations. (Write new program) 1) Display current contents of the file. 2) Add one more item at the end of file. 3) Again display contents of appended file. 4) Display total no. of objects in the file. 5) Display total no. of bytes in the file. 6) Take item no. from the user, modify the details of that item. 7) Again display contents of modified file. 8) Use proper error handling functions to prevent errors */ #include <iostream.h> #include <conio.h> #include <fstream.h> #include <string.h> int main() {     clrscr();     char ch;     ifstream in;     in.open("inventory.txt");     while ((ch = in.get()) != EOF)     { cout << ch;     }     streampos begin, end;     in.open("inventory.txt");     begin = in.tellg();     in.seekg(0, ios::end);     end = in.tellg();     in.close()...

2.Write a program of an inventory system. Define one class inventory having data members as 1. int code; 2. char itemname[10]; 3. float cost; and define required member functions. Define main function to read 10 items from the user and write that data in a file. Read that file and display information of all 10 items using proper output formatting.

/* j_5_p_2 Write a program of an inventory system. Define one class inventory having data members as 1. int code; 2. char itemname[10]; 3. float cost; and define required member functions. Define main function to read 10 items from the user and write that data in a file. Read that file and display information of all 10 items using proper output formatting. */ #include <iostream.h> #include <conio.h> #include <fstream.h> #include <string.h> #include <iomanip.h> class inventory { public: int code[10]; char itemname[10][10]; float cost[10]; public: void getdata() { ofstream out("inventory.txt"); out <<"\n-----------------------------------------------\n"; out << "\tcode\titemname\tcost"<< endl; out <<"-----------------------------------------------\n"; cout.precision(2); out.precision(2); for (int i = 0; i < 5; i++) { cout << "Ent...

8.Write a c++ program, which accepts two filename from command line appends the content of second file to first file. It should also display the content of the first file after appending.

 /*J_5_P_8 Write a c++ program, which accepts two filename from command line appends the content of second file to first file. It should also display the content of the first file after appending. */ #include <bits/stdc++.h>  using namespace std;     int main()  {      fstream file;          ifstream ifile("file2.txt", ios::in);      ofstream ofile("file.txt", ios::out | ios::app);          if (!ifile.is_open()) {          cout << "file not found";      }      else {          ofile << ifile.rdbuf();      }      string word;         file.open("file2.txt");         while (file >> word) {          cout << word << " ";      }      ...

7.Write a program that accepts any file name from the command line and copies the contents of the file to a new temporary file.

 /*J_5_P_7 Write a program that accepts any file name from the command line and copies the contents of the file to a new temporary file. */ #include <iostream.h> #include <conio.h> #include <fstream.h> void main(int argc[], char *argv[]) { ifstream obj1; ofstream obj2; char ch; clrscr(); obj1.open(argv[1]); obj2.open("temp.txt"); while(obj1.eof() == 0) {        obj1 >> ch;        obj2 << ch; } cout << "File copy...";   obj1.close();   obj2.close();   getch(); }

6.Write a C++ program, which accepts any filename from command line and displays total no. of characters, total no of words and total no of lines in that file.

 /*J_5_P_6 Write a C++ program, which accepts any filename from command line and displays total no. of characters, total no of words and total no of lines in that file. */ #include<iostream> #include<fstream> #include<string.h> #include<cstdlib> using namespace std; int main() {      int noc=0,now=0,nol=0;      FILE *fr;      char ch;           fr=fopen("abc.txt","r");           while(ch!=EOF)      {           if(ch!=' ' && ch!='\n')                noc++;           if(ch==' ')                now++;           if(ch=='\n')           {                nol++;                now++; ...

5. Write a program to enter 25 characters from the user. Check all the characters one by one, if it is a digit store it in digit.txt file, if it is a special symbol store it in special.txt file, if it is an alphabet than store it in alphabet.txt file. Use command line arguments

/*J_5_P_5 Write a program to enter 25 characters from the user. Check all the characters one by one, if it is a digit store it in digit.txt file, if it is a special symbol store it in special.txt file, if it is an alphabet than store it in alphabet.txt file. Use command line arguments */ #include <iostream.h> #include <conio.h> #include <fstream.h> void main(int argc[], char *argv[]) { ofstream obj1, obj2, obj3; obj1.open(argv[1]); obj2.open(argv[3]); obj3.open(argv[5]); clrscr(); char ch[25]; for (int i = 0; i < 15; i++) { cout << "Enter any digit, chracter and symbol:"; cin >> ch[i]; if (ch[i] >= 48 && ch[i] <= 57) obj1 << ch[i] << endl; else if ((ch[i] >= 65 && ch[i] <= 90) || (ch[i] >= 97 && ch[i] <= 122)) obj2 << ch[i] << endl; else obj3 << ch[i] << endl; } getch(); }

4.Take 10 numbers from the user, check all the number one by one, if it is an odd number, store it in odd.txt file, if it is an even number, store it in even.txt file. Use command line arguments.

/* j_5_P_4 Take 10 numbers from the user, check all the number one by one, if it is an odd number, store it in odd.txt file, if it is an even number, store it in even.txt file. Use command line arguments. */ #include <iostream.h> #include <conio.h> #include <fstream.h> void main(int argc[], char *argv[]) { ofstream obj1; ofstream obj2; int no; clrscr(); obj1.open(argv[1]); obj2.open(argv[3]); do { cout << "Enter Any no: "; cin >> no; if( no % 2 == 1 ) { obj1 << no << endl; } else { obj2 << no << endl; } } while(no != 0); obj1.close(); obj2.close(); getch(); }

1.Write a program of writing binary file. Take two arrays 1) Roll no. of 10 students 2) Marks of 10 students Write information of both the arrays in one file and again read it form the file.

 /* J_5_P_1 Write a program of writing binary file. Take two arrays 1) Roll no. of 10 students 2) Marks of 10 students Write information of both the arrays in one file and again read it form the file.   */ #include <iostream.h> #include <conio.h> #include <fstream.h> void main() { clrscr(); ofstream out("student.txt"); int rno[10]; int mark[10]; for (int i = 1; i < 10; i++) { cout << "Enter student Roll No. : "; cin >> rno[i]; out << rno[i]; cout << "Enter student Marks. : "; cin >> mark[i]; out << mark[i]; } out.close(); ifstream in("student.txt"); cout << "Roll No\t Marks\n"; for (i = 1; i < 10; i++) { cout << rno[i] <<"\t  " << mark[i] << endl; } in.close(); getch(); }