Writing and Reading student data in a file. Detailed Description: Write a progra
ID: 3612352 • Letter: W
Question
Writing and Reading student data in a file.
Detailed Description:
Write a program in which you have to:
Roll NO Student Name Class
101 AliRaza BS(CS)
102 Usman MS(CS)
103 Faizan BS(CS)
104 Rehan MIT
3. Open file and read data from it and display on thescreen.
Sample Output
Roll NO Student Name Class
101 AliRaza BS(CS)
102 Usman MS(CS)
103 Faizan BS(CS)
104 Rehan MIT
105 Ahmed MCS
Explanation / Answer
#include <isotream> #include <fstream> #include <cstdlib> #include <string> using namespace std; int main () { int num; string name; string field; ofstream outFile ( "myData.txt", ios::out ); ifstream inFile ( "myData.txt", ios::in ); cout << "Enter your Roll Number, followed by a spacethen name again followed by sapce " << "and again type your Displine, tostop data entering press <ctrl+z> "; while ( cin >> num >> name >> field ) { outFile << num << ' ' << name << ' '<< field << endl; } cout << " Data showing on screen. "; cout << " Roll Number Name Discipline<< endl; while ( inFile >> num >> name >> field) { cout << num << " " << name <<" " << field << endl; } system ( "pause" ); return 0; } At the last dear one, i have not compiled this code, there may be someerrors, you have to correct them I have less time. I have given you an idea. Now you have to polish you code by yourown..................... best of luckRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.