#include <iostream>
#include <stdio.h>
#include <conio.h>
usingnamespace std;
class student
{
private :
int nr;
staticint count;
char name[20];
int age;
char phone [11];
public :
student() : nr(count)
{
++count;
}
int getID() {return nr;}
staticint getCount() {return count;}
void Getdata()
{
cout << "Enter Student Name "; cin >> name;
cout << "Enter Student Age "; cin >> age;
cout << "Enter Student Phone Number "; cin >> phone;
}
void Putdata()
{
cout << "Student name :" << name;
cout << "Student age :" << age;
cout << "Student phone number :" << phone;
}
};
int main()
{
student s;
s.Getdata();
s.Putdata();
return 0;
}
Assignment:
Create a class, called studentClass. It should have following data members:
• Name
• Age
• Telephone Number
It should also have member function to set and display these data members. It should have two constructors; one a default constructor which sets Name to blank, Age to 0 and Telephone Number to blank and other constructor should have three parameters which sets the value of these three data members to the values passed in the parameters.
This class should also have a static data member which keeps track how may objects of this class have been created.
Write a test program (main), which creates individual objects of this class (like studentClass a, studentClass b), creates objects using new operator, creates array of the objects like (studentClass c[5]), delete the objects created by new operator. After each of these operations, please display the total number of objects at each stage using the static data member.
The static variable needs to be created somewhere, once, because it is not created each time an instance of the class is created like all the non-static variables.
I already showed you. You have to create the variable count somewhere. Because it is static it does not get created with the rest of the class. Go back to the code I posted and look at line 37.
omg, I totally missed your line 37. I even checked what you'd posted line by line with my code (supposedly). Ugh! Sorry about that.
Ok, so I'll delete my Count class and use your line 37 instead.
Thank you!
What about my "two constructors; one a default constructor which sets Name to blank, Ag to 0 and Telephone Number to blank and other constructor should have three parameters which sets the balue of these three data members to the values passed int he paramaeters"
Did I add those correctly in the header and cpp files above?