A company wants to offer bursary to deserving students of a class of fifty. Information available for each
student is: ID number (string 3 characters) , Name (string of 10 Characters), Date of birth (day, month,
year), marks of 6 modules; mark are between 0 and 100. A student deserves a bursary if the average of
her/his marks is equal or more than 70% and she/he does not have a mark less than 60% in any of her/his
modules.
Â
#include <iostream>
using namespace std;
class Student{
    char id[3], name[10];
    int day, month, year;
    float marks[6], sum = 0, average;
    public:
    Student(){
        cout<<"Enter student id: ";
        cin>>id;
        cout<<"Enter student name: ";
        cin>>name;
        cout<<"Enter date of birth\nEnter year: ";
        cin>>year;
        cout<<"Enter month: ";
        cin>>month;
        cout<<"Enter day: ";
        cin>>day;
        for(int i = 0; i < 6; i++){
            cout<<"Enter marks of module "<<i + 1<<": ";
            cin>>marks[i];
            if(marks[i] < 0 || marks[i] > 100){
                cout<<"\nMarks should be between 0 and 100\n";
                i--;
            }
            else{
                sum += marks[i];
            }
        }
        average = sum / 6;
    }
    bool bursary_qualify(){
        if(average < 70) return false;
        else{
            for(int i = 0; i < 6; i++) if(marks[i] < 60) return false;
        }
        return true;
    }
    friend ostream &operator<<(ostream& out, const Student& student){
        out<<student.name<<" (id = "<<student.id<<")";
        return out;
    }
};
int main(){
    for(int i = 0; i < 50; i++){
        Student student = Student();
        cout<<student;
        if(student.bursary_qualify()){
            cout<<" has qualified for bursary\n";
        }
        else cout<<" has not qualified for bursary\n";
    }
    return 0;
}
Comments
Leave a comment