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
|
#include <iostream>
using namespace std;
void part2(); // declaration for the part2() function
class Student
{
private:
int KUID; //Stores the student's KUID number
double HomeworkAvg; //Stores the student's average on Homework
double QuizAvg; //Stores the student's average on Quizzes
double ExamAvg; //Stores the student's average on Exams
public:
friend ostream output_friend (ostream& outs, Student person1);
// Constructors
Student(); //Default Constructor
//Overloaded constructor that gives the attributes values passed in.
Student(int k, double h, double q, double e);
// Accessors (Get Methods)
// Remember when we write get methods, they always have the same return
// type as the attribute they are "getting" and never take any parameters.
int getKUID();
double getHomeworkAvg();
double getQuizAvg();
double getExamAvg();
// Mutators (Set Methods)
// When we write set methods, they always have void as their return type. They
// have one parameter of the same type of the attribute they are "setting."
void setKUID(int k);
void setHomeworkAvg(double h);
void setQuizAvg(double q);
void setExamAvg(double e);
// Additional Functions
void print();
void average();
ostream output_friend (ostream& outs, Student person1);
{
cout<<"KUID"<<KUID<<endl;
cout<<"Homework AVG"<<HomeworkAvg<<endl;
cout<<"Quiz AVG"<<QuizAvg<<endl;
cout<<"Exam AVG"<<ExamAvg<<endl;
}
return 0;
}; //Don't forget your semicolon here!
int main()
{
int labChoice = 0;
cout << "Lab 10\n";
do
{
cout << "Which part of the lab are you working on? " << endl
<< "\t1 - Part 2 (Classes)\n\t2 - Quit\n\n"
<< "Please enter your choice: ";
cin >> labChoice;
switch(labChoice)
{
case 1:
part2();
break;
case 2:
break;
default:
cout << "Invalid Selection. Try again!\n";
}
} while(labChoice != 2);
return 0;
}
// ***Write all function definitions outside of any function definition***
Student::Student():KUID(0),HomeworkAvg(0.0),QuizAvg(0.0),ExamAvg(0.0)
{
}
Student::Student(int k, double h, double q, double e)
{
KUID=k;
HomeworkAvg = h;
QuizAvg = q;
ExamAvg=e;
}
int Student::getKUID()
{
return KUID;
}
double Student::getHomeworkAvg()
{
return HomeworkAvg;
}
double Student::getQuizAvg()
{
return QuizAvg;
}
double Student::getExamAvg()
{
return ExamAvg;
}
void Student::print()
{
cout<<"KUID:\t\t"<<KUID<<endl;
cout<<"HomeworkAvg:\t"<<HomeworkAvg<<endl;
cout<<"QuizAvg:\t"<<QuizAvg<<endl;
cout<<"ExamAvg:\t"<<ExamAvg<<endl;
}
void Student:: average()
{
cout<<"Evenly averaged score is:"<<(HomeworkAvg+QuizAvg+ExamAvg)/3<<endl;
}
// *** PART 2 CODE BELOW
void part2()
{
// Complete the instruction underneath each comment given below:
// -------------------------------------------------------------
// Declare an object of the class 'Student'
Student st1;
// Use the overloaded constructor to pass in 84551 for the KUID,
// 78.5 for the HomeworkAvg, 87.25 for QuizAvg, and 77.0 for the ExamAvg.
st1 = Student(84551,78.5,87.25,77.0);
// Have your Student object call the functions average and print
output_friend(cout, st1);
}
|