Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i hav a problem with codin a method that will add students to Class Course. this is what i have
#include <iostream>
using namespace std;class Student //class declaration
{
string name; //class data member
int idNum; //class data member
double gpa; //class data member
public:
void set_data(string nom, int id, double result)
{
name = nom;
idNum = id;
gpa = result;
}
void display_data()
{
cout << "Student name is " << name << endl;
cout << "Student id is " << idNum << endl;
cout << "GPA is " << gpa << endl;
}
};class Course: public Student
{
string course_name;
public:
void get_data()
{
cout << "enter the name of the course:";
cin >> course_name;
cout << endl;
}void add_students(string name[],int size)
{
cout << "how many students you want to add?";
cin >> size;
int i = 0;
string next;
while (i < size)
{
name[i] = next;
i ++;
cin >> next;
}
}};
int main()
{
string name;
int size, i;
Course n;
n.get_data();
n.set_data("Nomsa", 10016666, 3.14);
n.display_data();
n.add_students( name ,size);
return 0;
}

![]() |
Not trusted sites
|
how to read certain lines...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |