PURPOSE c learn to work with arrays structures and IO to be
PURPOSE:
c++
learn to work with arrays, structures, and I/O
to be familiar with Visual Studio environment
Description:
In this assignment, please write a program that provides a way for you to search and display information of all students in the class. Student records including c# and scores of multiple categories are saved in the file point.dat. Your program should: • First, read all student information from the text file and store them in an array.
Prompt user to input a valid c#, and the program display all information of the student with the given c#.
Then display information of all students. Requirements
You are required to
declare a structure Student to hold all information of a student, such as C# and all scores.
declare a local variable Roster in main function as an array of Student structure. This array will hold information of all students.
declare and implement the following functions:
a function to read from the text file o a function to print one student
a function to print information of all students
the name of the source file must be: ola1.cpp.
Global variables are not allowed.
here\'s the file:
ID CLA OLA Quiz Homework Exam Bonus Total FinalGrade
c088801 10 15 4 15 56 5
c088802 9 12 2 11 46 2
c088803 8 10 3 12 50 1
c088804 5 5 3 10 53 3
c088805 3 11 1 10 45 0
c088806 8 14 2 11 40 -1
c088807 4 12 2 12 48 -2
c088808 10 10 3 11 36 0
c088809 8 8 3 11 39 0
c088810 6 9 4 9 47 3
c088811 8 7 3 13 41 3
c088812 4 11 3 11 37 1
c088813 9 15 2 8 50 2
c088814 8 12 2 10 48 4
c088815 6 8 1 7 45 1
c088816 7 7 2 6 51 2
c088817 8 9 2 12 38 2
Solution
Here is the C++ code for you, as per your requirements:
#include <iostream>
#include <fstream>
using namespace std;
//declare a structure Student to hold all information of a student, such as C# and all scores.
typedef struct Student
{
string ID;
int CLA;
int OLA;
int Quiz;
int Homework;
int Exam;
int Bonus;
int Total;
char FinalGrade;
}Student;
//a function to read from the text file
int readFile(ifstream &fin, Student Roster[])
{
string temp;
getline(fin, temp);
int count = 0;
while(!fin.eof())
{
fin>>Roster[count].ID>>Roster[count].CLA>>Roster[count].OLA>>Roster[count].Quiz;
fin>>Roster[count].Homework>>Roster[count].Exam>>Roster[count].Bonus;
count++;
}
return count;
}
//a function to print one student
void printStudent(Student Roster[], string ID, int count)
{
for(int i = 0; i < count; i++)
if(Roster[i].ID == ID)
{
cout<<\"ID: \"<<Roster[i].ID<<endl;
cout<<\"CLA: \"<<Roster[i].CLA<<endl;
cout<<\"OLA: \"<<Roster[i].OLA<<endl;
cout<<\"Quiz: \"<<Roster[i].Quiz<<endl;
cout<<\"Homework: \"<<Roster[i].Homework<<endl;
cout<<\"Exam: \"<<Roster[i].Exam<<endl;
cout<<\"Bonus: \"<<Roster[i].Bonus<<endl;
cout<<\"Total: \"<<Roster[i].Total<<endl;
cout<<\"FinalGrade: \"<<Roster[i].FinalGrade<<endl;
}
}
//a function to print information of all students
void printAllStudents(Student Roster[], int count)
{
for(int i = 0; i < count; i++)
printStudent(Roster, Roster[i].ID, count);
}
int main()
{
//declare a local variable Roster in main function as an array of Student structure.
Student Roster[30];
//First, read all student information from the text file and store them in an array.
ifstream fin;
fin.open(\"point.dat\");
int count = readFile(fin, Roster);
//Prompt user to input a valid c#
cout<<\"Enter the C# to search the student details: \";
string ID;
cin>>ID;
//display all information of the student with the given c#.
printStudent(Roster, ID, count);
//Then display information of all students.
printAllStudents(Roster, count);
}


