We have been instructed among many things to "Notice that the cost is totaled and the hours are totaled. These values are not stored but computed for the sole purpose of being displayed to the screen. Since the number of hours and individual cost is stored, there is no reason to store the totals. (See totalhours)
I have written this and all works but the total.
#include<iostream.h>
#include <stdlib.h>
#include <stdio.h>
class Student
{
public:
char firstName[25];
char lastName[25];
char address[50];
char city[25];
char state[10];
char zipcode[11];
int studentCounter;
int courseCounter;
char SID [7];
char courseNumber[7][25];
char courseTitle[7][25];
int courseHours[7];
};
Student createStudent(Student newStudent)
{
int StudentCounter = 0;
int y = 0;
cout << "Enter the student\'s first name: ";
cin.getline(newStudent.firstName, 25, '\n');
cout << "Enter the student\'s last name: ";
cin.getline(newStudent.lastName, 25, '\n');
cout<<"Enter street address: ";
cin.getline(newStudent.address,50,'\n');
cout<<"Enter city: ";
cin.getline(newStudent.city,25,'\n');
cout<<"Enter state: ";
cin.getline(newStudent.state,10,'\n');
cout<<"Enter zip code: ";
cin.getline (newStudent.zipcode,11,'\n');
y = 0;
do
{
cout<<"Enter a course Number\t";
cin.getline (newStudent.courseNumber[y],25,'\n');
cout<<"Enter course Name\t";
cin.getline (newStudent.courseTitle[y],25,'\n');
cout<<"Enter the number of hours\t";
cin>>newStudent.courseHours[y];
newStudent.courseCounter++;
cin.ignore();
y++;
}
while (y<3);
newStudent.studentCounter++;
sprintf (newStudent.SID, "%c%c-%d",newStudent.firstName[0], newStudent.lastName[0], newStudent.studentCounter);
return newStudent;
}
void displayStudent(Student newStudent)
{
int totalHours = 0;
int y = 0;
do
{
cout<<totalHours = totalHours + newStudent.courseHours[y];
y++;
}
while (y<newStudent.courseCounter);
endl;
}
void main()
{
Student student; //declare one student for class Student
int menuChoice;
cout<<"Menu of choices: "<<endl;
cout<<"1) Enter a new student "<<endl;
cin>>menuChoice;
cin.ignore();
switch (menuChoice)
{
case 1: student = createStudent(student);
cout << endl << endl;
cout<<"Menu of choices: "<<endl;
cout<<"1) Enter a new student "<<endl;
cout<<"2) Display student and list of classes "<<endl;
cout<<"3) Print a student's bill "<<endl;
cout<<"4) Exit"<<endl;
cin>>menuChoice;
cin.ignore();
case 2: displayStudent(student);
cout << endl << endl;
}
system ("Pause");
}