Vajclav 0 Newbie Poster

I want to add a try catch block in the CalculateAverageRate method where I want the user to enter grades 1,2,3,4,5 and for other numbers to throw an exception... I would also like to make a constructor with three parameters (string name, string surname, string date_birth) in which string attributes are set to the values sent through the parameters and numeric attributes to 0. I made a constructor without parameters (at least I think I did if anyone can to tell me if it's true) but now I want to make this constructor as well

#include <iostream>
#include <stdio.h>
using namespace std;

class Student
{
private:
    string name;
    string surname;
    string date_birth;
    double average_grade;

public:
    Student ()
    {
        name = "";
        last name = "";
        date_birth = "";
        average_grade = 0;
    }
void ChangeBasicData ()
{
    cout << "Enter name:" << endl;
    cin >> name;
    cout << "Enter last name:" << endl;
    cin >> surname;
    cout << "Enter date of birth:" << endl;
    cin >> date_birth;

}

void CalculateAverageRate (/ * int argc, char ** argv * /)
{
float x = 0;
int i;
int a;
int size;

cout << "Enter the number of grades for which you want to calculate the arithmetic mean.";
cin >> size;
for (i = 1; i <= size; i ++) {
    cout << "Enter grade #" << and << ":";
    cin >> a;
    x + = a;
    average_grade = x / (float) size;
}

cout << "The arithmetic mean of your grades is:" << average_grade << endl;
}

void PrintData ()
{
    cout << "Your name is:" << name << '\ n';
    cout << "Your last name is:" << surname << '\ n';
    cout << "Your date of birth is:" << date_birth << '\ n';
    cout << "Your average rating is:" << average_grade << '\ n';
}
};

int main ()
{
       Student obj;
       int i;
       enter:
       cout << "Enter which option you want:" << endl;
       cout << "1. Enter your details" << endl;
       cout << "2. Calculate the average grade" << endl;
       cout << "3. Show all" << endl;
       cout << "4. End of program" << endl;
       cin >> i;
   switch (s) {
      case 1:
        obj.ChangeBasicData ();
        goto enter;
        break;
      case 2:
        obj.CalculateAverageRate ();
        goto enter;
        break;
      case 3:
        obj.PrintData ();
        goto enter;
      case 4:
        cout << "Thanks for the info" << endl;
        break;
      default:
        goto enter;
    }
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.