0

can anyone solve this problem for me ???
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#include<iostream>
#include<string>
#define size 10

using namespace std;

struct student {
string name;
int id;
string prog;
double cgpa;
};


class stinfo {
    private:
        student data[size];
        int last;
    public:
        stinfo();
        void add(string name, int id, string prog, double cgpa);


};

stinfo :: stinfo()
{
    last = 0 ;
}


void stinfo::add(string name, int id,string prog, double cgpa)
{
    if (last == data[size]) {
    return ;
}
data[last].name = name;
data[last].id = id;
data[last].prog = prog;
data[last].cgpa = cgpa;
++last;
}



int main()
{
    char ans;
    string name1,prog1;
    int id1;
    double cgpa1;

    stinfo st;

    cout <<endl;
        cout <<">>>>> INSERT NEW STUDENT INFORMATION <<<<<"<<endl;

        cout <<"NAME : ";
        cin >>name1;

        cout <<"ID: ";
        cin >>id1;

        cout <<"PROGRAMME : ";
        cin >>prog1;

        cout <<"CGPA: ";
        cin >>cgpa1;

        st.add ( name1,id1,prog1,cgpa1 );

        system("pause");
    return 0;


}

`

2
Contributors
1
Reply
12
Views
4 Years
Discussion Span
Last Post by Lucaci Andrew
1

can anyone solve this problem for me ???

We're not here to solve your homework, we're here to help you figure out how YOU can solve it.

Class Array

vaguely defined situation, what should we look for?

 if (last == data[size])

presumably should be

 if (last == size)

because you want to see if you've reached your end of the array.
And as a programming concept, macros are in upper-case letters, so:

#define size 10

would be

#define SIZE 10

Edited by Lucaci Andrew

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.