I had to make a class student that would have attributes string name, string surname, string date, double average mark.
Class must have a parameterless constructor (in which all string attributes are set to an empty string, i.e. “”, and numerical attribute to 0) and the constructor with 3 parameters (string I, string p, string dr) at which these parameters are assigned to appropriate string attributes, and the numerical attribute is set again at 0.
void change Data () within which a value entry should be requested for the name, surname and date of birth by the user and then assign these values to appropriate attributes
void Invoice average () within which it is necessary to input 5 evaluations (1-5) by users and calculate their average, and place this value in the corresponding class attribute. What I don't understand is that we have to throw an exception unless some value of validity is entered for evaluation. The correct entry is therefore an evaluation (1,2, 3,4, 5) and any other entry should cause the exemption to be thrown. This exception must be “caught” in the main function where the calls of this method are tested, with the TRY-catch block. In the catch section we must print only some information message that will tell the user that he did not enter the correct data. I ran into a lot of problems, and I need some help. Thank you.
#include <iostream>
#include <string>
#include <conio.h>
#include <stdio.h>
#define MAX 10
using namespace std;
class Student {
private:
string name ;
string surname ;
string date_birth ;
double eng, grm, art, sng, math;
double average_mark;
double taverage_mark() {
return (eng + grm + art + sng + math)/5;
}
public:
void ChangeP(void);
void CalculateP(void);
void PasteP(void);
};
void Student::ChangeP(void) {
cout << "ENter your name " << endl;
cin >> name;
cout << "Enter your surname " << endl;
cin >> surname;
cout << "Enter your birth date " << endl;
cin >> date_birth;
average_mark = taverage_mark();
}
void Student::CalculateP(void) {
cout << "Enter your mark in english ";
cin >> eng;
if (!(eng >= 0 && eng <= 5)) {
throw static_cast<string>("Error!");
}
cout << "Enter your mark in art ";
cin >> art;
if (!(art >= 0 && art <= 5)) {
throw static_cast<string>("Error!");
}
cout << "Enter your mark in music class ";
cin >> sng;
if (!(sng >= 0 && sng <= 5)) {
throw static_cast<string>("Error!");
}
cout << "Enter your mark in german ";
cin >> grm;
if (!(grm >= 0 && grm <= 5)) {
throw static_cast<string>("Error!");
}
cout << "Enter your mark in math ";
cin >> math;
if (!(math >= 0 && math <= 5)) {
throw static_cast<string>("Error!");
}
average_mark = taverage_mark();
}
void Student::PasteP() {
cout << "Name " << name << "\nSurname " <<surname
<< "\nDate of birth" << date_birth << "\nEnglish " << eng
<< "\nGerman " << grm << "\nArt " << art
<< "\nMusic" << sng << "\nArt" << art
<< "\nAverage mark " << average_mark;
}
int main() {
Student std[MAX];
int n, loop;
double eng = 0, njem = 0, lik = 0, bos = 0, muz = 0;
cout << "Enter number of students: ";
cin >> n;
for (loop = 0; loop < n; loop++) {
cout << "Enter details of student " << loop + 1 << ":\n";
std[loop].ChangeP();
}
cout << endl;
for (loop = 0; loop < n; loop++) {
cout << "Enter marks " << loop /1 << ":\n";
std[loop].CalculateP();
}
for (loop = 0; loop < n; loop++) {
cout << "DEtails of student " << (loop + 1) << ":\n";
std[loop].PasteP();
}
try {
cout << "Mark is " << eng << endl;
}
catch (const string exception) {
cerr << "Error: " << exception << endl;
}
return 0;
}