Answer to Question #6678 in C++ for noor

Question #6678
Using ( Arrays ,String and Function )
Write a program in C++ , whose objective is to help an instructor in a University to indicate the status of students absences from classes.
For a certain instructor the program should be designed to handle a maximum of 6 courses. Courses are categorized according to their number of contact hours per week ( 50 minutes , 75 minutes or 180 minutes ) . The semester is assumed as 14 weeks .
The program is initialized for each course by students IDs for that course. The program prompt the instructor to choose a course from a menu showing his /her courses ( or to exit the program ).

For the course selected the prompt will ask the instructor to enter the number of times the student been absent for that course .
Once all numbers are entered the program will calculate the percentage of absence considering the number of week s and the category of the course and a report is produced by the program showing appropriate mes
1
Expert's answer
2012-02-23T10:10:58-0500
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <istream>

using namespace std;
struct IDs
{
string ID;
int absent;
};

void main ()
{
ofstream fo;
ifstream fi;
vector < vector <IDs> > IDsArr(6);
int mass[6] = {};
int week[6] = {};
cout<<"Enter data, or read to file? 1/0\n";
bool ok; cin>>ok;
if (ok)
{
& fo.open("course.txt");
& cout<< "Enter number course (from 1 to 6)\n";
& int course; cin>>course;

& cout<< "Enter minutes in weeks (50, 75 or 180)\n";
& int minutes; cin>>minutes;
& mass[course] = minutes;

& cout<<"Enter number weeks\n";
& int weeks; cin>>weeks;
& week[course] = weeks;
& cout<< "Enter data: ID, minutes absent in years (exit Ctrl+Z)\n";
& IDs id;
& while (cin>>id.ID)
& {
& cin>>id.absent;
& IDsArr[course].push_back(id);
& IDs id;
& }
& for (int i = 0 ; i < IDsArr.size() ; i++)
& {
& fo<<"-1"<<' '<<i<<' '<<mass[i]<<' '<<week[i]<<endl;
& for (int j = 0 ; j < IDsArr[i].size() ; j++)
& {
& fo<<IDsArr[i][j].absent<<' ' <<IDsArr[i][j].ID<<endl;
& }
& }
& fo.close();
& cin.clear();

& for (int i = 0 ; i < IDsArr.size() ; i++)
& {
& cout<<"course "<<i<<endl;
& for (int j = 0 ; j < IDsArr[i].size() ; j++)
& cout<<"Student : "<< IDsArr[i][j].ID<< " absent "
& lt;<IDsArr[i][j].absent << " with " << mass[i]*week[i] << " minutes in "
& lt;<week[i]<< " weeks"<<endl;
& }
}
else
{
& fi.open("course.txt");
& if (!fi) cout<<"error\n", exit(0);
& int course = 0;
&
& while (!fi.eof())
& {
& IDs a;
& fi>>a.absent;
& if (a.absent == -1)
& {
& fi>>course;
& fi>>mass[course];
& fi>>week[course];
& }
& else
& {
& fi>>a.ID;
& IDsArr[course].push_back(a);
& }
& }
& for (int i = 0 ; i < IDsArr.size() ; i++)
& {
& cout<<"course "<<i<<endl;
& for (int j = 0 ; j < IDsArr[i].size() ; j++)
& cout<<"Student : "<< IDsArr[i][j].ID<< " absent "
& lt;<IDsArr[i][j].absent << " with " << mass[i]*week[i] << " minutes in "
& lt;<week[i]<< " weeks"<<endl;
& }
}


system ("pause");
return;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS