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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
void studentDetails(string&, string&, string&);
void getMarks(double[], string[], int);
double calcAverageYearMark(double[], int);
void minmaxIndex(double[], int, int&, int&);
bool passOrFail(int);
bool distinction(int);
void getCode(int, int&, string&);
void displayReport(string, string, string, double[], string[], int);
int main()
{
const int NO_SUBJECTS{6};
double marks[NO_SUBJECTS]{0};
string subject[NO_SUBJECTS]
{
"English","Mathematics","Life Orientation","History",
"Computer Literacy","Art"
};
string name, surname, school;
studentDetails(name, surname, school);
getMarks(marks, subject, NO_SUBJECTS);
displayReport(name, surname, school, marks, subject, NO_SUBJECTS);
return 0;
}
void studentDetails(string& nm, string& sn, string& sc)
{
cout << " Please key in your name: ";
std::getline(std::cin, nm);
cout << " Please key in your surname: ";
std::getline(std::cin, sn);
cout << "Please key in the name of your school: ";
std::getline(std::cin, sc);
}
void getMarks(double mks[], string subj[], int no_subj)
{
for(int i = 0; i < no_subj; i++)
{
cout << "Key in your mark for " << subj[i] << ": ";
cin >> mks[i];
}
}
double calcAverageYearMark(double mks[], int no_subj)
{
double totMark{0};
for(int i = 0; i < no_subj; i++)
{
totMark += mks[i];
}
return totMark/no_subj;
}
void minmaxIndex(double mks[], int no_subj, int& mini, int& maxi)
{
double min{1000};
double max{-1};
for (int i = 0; i < no_subj; ++i)
{
if (mks[i] < min)
{
min = mks[i];
mini = i;
}
if (mks[i] > max)
{
max = mks[i];
maxi = i;
}
}
}
bool passOrFail(int mks)
{
if(mks >= 50)
return true;
else
return false;
}
bool distinction(int mks)
{
if(mks >= 75)
return true;
else
return false;
}
void getCode(int mks, int& code, string& grade)
{
if(mks > 80)
{
code = 7;
grade = "A";
}
else if( mks > 70)
{
code = 6;
grade = "B";
}
else if(mks > 60)
{
code = 5;
grade = "C";
}
else if(mks > 50)
{
code = 4;
grade = "D";
}
else if(mks > 40)
{
code = 3;
grade = "E";
}
else if(mks > 30)
{
code = 2;
grade = "F";
}
else
{
code = 1;
grade = "FF";
}
}
void displayReport(string nm, string sn, string sc, double mks[], string subj[], int no_subj)
{
cout
<< "REPORT FOR:\n"
<< " NAME: " << nm << " SURNAME: " << sn
<< " SCHOOL: " << sc << "\n\n";
int code{0};
string grade;
for(int i = 0; i < no_subj; i++)
{
cout
<< setw(3) << i << ' ' << setw(20) << subj[i] << '\t' << mks[i] << '\t';
if( passOrFail(mks[i]) )
cout << "Pass";
else
cout << "Fail";
if( distinction( mks[i]) )
cout << " Distinction";
getCode(mks[i], code, grade);
cout << " Code: " << code << " Grade: " << grade;
cout << '\n';
}
double average_mark = calcAverageYearMark(mks, no_subj);
cout << "Average marks: " << average_mark;
if( distinction( average_mark ) )
cout << " Distinction";
cout << '\n';
int min_index{0};
int max_index{0};
minmaxIndex(mks, no_subj, min_index, max_index);
cout << "Min marks: " << mks[min_index] << '\n';
cout << "Max marks: " << mks[max_index] << '\n';
}
|