Question? C++ programming 1 Assuming you have an input file variable called \"st
ID: 3696589 • Letter: Q
Question
Question? C++ programming 1 Assuming you have an input file variable called "stuinfo" already created, write the code which will read in student information from an input file. Save the data using the student array variables declared in the previous question. Write the code so that program will be able to process an unknown number of student records. When finished reading in the student records, output all of the student data back to the screen. Only the code needed to complete the above is necessary.Explanation / Answer
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
using namespace std;
class Student
{
public:
int id;
string name;
int marks;
};
int main()
{
Student s[100000]; // Student array of size 100000
int n,i=0;
ifstream infile("stuInfo.txt"); // file which contains sudents information
int id, marks;
string name;
while (infile >> id >> name>>marks) // reading and assigning values to each student
{
s[i].id = id;
s[i].name = name;
s[i].marks = marks;
i++;
}
n=i;i=0;
while (i<n) // printing the each student's information
{
cout<<"student's id:"<<s[i].id<<" name: "<<
s[i].name<<" marks: "<<
s[i].marks<<endl;
i++;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.