Computing.Net > Forums > Programming > stuck with Classes.

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

stuck with Classes.

Reply to Message Icon

Name: smoothes
Date: March 12, 2009 at 03:16:13 Pacific
OS: Windows XP
Subcategory: C/C++
Comment:

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;
}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Not trusted sites how to read certain lines...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: stuck with Classes.

help with classes in c++ www.computing.net/answers/programming/help-with-classes-in-c/11749.html

Stuck on GW-Basic! Help please! www.computing.net/answers/programming/stuck-on-gwbasic-help-please/3689.html

stuck with java homework www.computing.net/answers/programming/stuck-with-java-homework/3943.html