1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#define MAX 45
using namespace std;
struct Student {
string lastname;
string firstname;
string id;
int number_of_classes;
string classname[20];
char grade[20];
int units[20];
float GPA;
float points[40];
};
bool openFile(ifstream &fin);
void Read_info(Student &NewStudent, ifstream &fin);
void Print_info_one(Student NewStudent);
void Find_points(Student &NewStudent, char grade[]);
int Read_list(Student Stu_list[], int max_size);
void Print_list(Student Stu_list[], int size);
int main()
{
Student NewStudent[MAX], Stu_new;
ifstream fin;
int counter=0;
counter = Read_list(NewStudent, MAX);
for (int i = 0 ; i < counter; i++)
{
Find_points(Stu_new, Stu_new.grade[i]);
}
if(counter>0)
{
Print_list(NewStudent, counter);
}
else
cout << "Empty file. " << endl;
fin.close();
return 0;
}
bool openFile(ifstream&fin)
{
string file_name;
cout << " Enter file name including the path: ";
getline(cin, file_name);
fin.open(file_name.c_str());
if (fin.fail())
return false;
else
return true ;
}
int Read_list(Student Stu_list[], int max_size)
{
ifstream fin;
int i=0;
if (openFile(fin)==true)
{
Read_info(Stu_list[i], fin);
while(!fin.eof())
{
i++;
if (i==max_size)
{
cout << "\nArray is full. " << endl;
return (i);
}
Read_info(Stu_list[i], fin);
}
}
else
{
cout << "Bad file entered. " << endl;
exit(0);
}
return(i);
}
void Read_info(Student &NewStudent, ifstream &fin)
{
int size;
getline(fin, NewStudent.lastname, ',');
getline(fin, NewStudent.firstname);
getline(fin, NewStudent.id, ' ');
fin >> NewStudent.number_of_classes;
fin.ignore(10, '\n');
size = NewStudent.number_of_classes;
for (int i=0; i<size; i++)
{
getline(fin, NewStudent.classname[i]);
fin >> NewStudent.grade[i];
fin >> NewStudent.units[i];
fin.ignore(10, '\n');
}
}
void Print_info_one(Student NewStudent)
{
int size = NewStudent.number_of_classes;
cout << "\n\n\tName: " << right << setw(24) << NewStudent.lastname << "," << NewStudent.firstname <<endl;
cout << "\tID Number: " << right << setw(21) << NewStudent.id << endl;
cout << "\tNumber of classes: " << NewStudent.number_of_classes << endl;
cout << "\tCourse: " << NewStudent.classname[0] << endl;
for(int i=0; i<size; i++)
{
cout << "\tCourse 1 " << right << setw(18) << "Name: " << left << setw(14) << NewStudent.classname[i] << "Grade: " << left << setw(5) << NewStudent.grade[i] << "Units: " << NewStudent.units[i] << endl;
cout << "\tGPA: " << right << setw(21) << showpoint << fixed << setprecision(3) << NewStudent.GPA << endl << endl;
}
}
void Print_list(Student Stu_list[], int size)
{
for (int i = 0 ; i < size; i++)
{
cout << "\n\n\tName: " << right << setw(24) << Stu_list[i].lastname << "," << Stu_list[i].firstname <<endl;
cout << "\tID Number: " << right << setw(21) << Stu_list[i].id << endl;
cout << "\tNumber of classes: " << Stu_list[i].number_of_classes << endl;
for(int t=0; t < Stu_list[i].number_of_classes; t++)
{
cout << "\tCourse " << t+1 << right << setw(18) << "Name: " << left << setw(14) << Stu_list[i].classname[t] << "Grade: " << left << setw(5) << Stu_list[i].grade[t] << "Units: " << Stu_list[i].units[t] << endl;
cout << "\tPoints: " << right << setw(21) << showpoint << fixed << setprecision(3) << Stu_list[i].points[t]<<endl;
}
}
}
/*
The points are found using this function
*/
void Find_points(Student &NewStudent, char grade[])
{
Student Stu_list[45];
int size;
size= 0;
for (int i = 0 ; i < size; i++)
{
if (Stu_list[i].grade[i] == 'A')
Stu_list[i].points[i] = 4.0;
if (Stu_list[i].grade[i] == 'B')
Stu_list[i].points[i] = 3.0;
if (Stu_list[i].grade[i] == 'C')
Stu_list[i].points[i] = 2.0;
if (Stu_list[i].grade[i] == 'D')
Stu_list[i].points[i] = 1.0;
if (Stu_list[i].grade[i] == 'F')
Stu_list[i].points[i] = 0.0;
}
}
|