I need some help with this Class program

I am new to C++, and can not get this Student Class program to display "Name for student1 is unassigned and ssn is 9999999999." and "Name for student2 is John Doe and ssn is 123456789".

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  #include <iostream>
#include <iomanip>
#include <string>


using namespace std;

class Student
{
	private:
		
		char name[80]; // Student Name
		int SSN;      // Social Sercurity Number (SNN)
		
	public:	
	
	    student();
	    student(char name[80],int SNN);
	    void setstudent(char name[80]= unassigned,int SNN = 999999999); 
	    int setSSN;     // should not accept 1 argument and update
	    int getSSN();  // getSSN should return the class SSN
	    void char setname();
	    void char getname();
	    void display();
};

Student :: Student()
{
	Name = "Unassigned"; // A Default constructor
	SSN = 999999999;    // A Default constructor
	
}

Student :: Student(char Name[80],int SSN) 
{
	Name = "John Doe"; // Student Name
	SSN = 123456789;   // // Social Sercurity Number (SNN)
	
}

char Student :: getname()
{
	return name;
}

int Student :: getSSN()
{
	return SSN;
}

void Student :: display ()
{
	
	cout<<"Name for Student 1 is"<<name1<<"and"<<SSN1<<endl;
	cout<<"Name for Student 2 is"<<name2<<"and"<<SSN2<<endl;
	
}

int main ()
{
	
	int SSN1,SSN2;
	char name1, name2;
	display();
	
	return 0;
}Put the code you need help with here.
Ooops.... My Visual Studio report 18 errors... It may take a while to make this work. But for now:
-there`s no object in this class, without object it won`t work, if you need two results you must create two objects with different parameters;
-class Student has no member Student - line 34;
-line 19 - unassigned is undefined, should be "unassigned";
-line 17 and 18 - it should be Student;
-lines 22 and 23 - you can`t use void and type (char in this case) together, if function return value, then can`t be void (without returning value);
- in main() - as i mention, without object it has no sense;
To create object in class Student:
Student object_name;
this will create one object using default constructor.
Now you can use only public components, private variables (and anything else in private) can be accessed ONLY by public methods.
...and many more, if i find some time i try to clean this mess...;-)
Here it is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Student
{
private:

	string name; // Student Name
	int SSN;      // Social Sercurity Number (SNN)

public:

	Student();//default constructor
	Student(string name, int SSN) ;//constructor
	string display_name();
	int display_ssn();
};

Student::Student()
{ 
	name = "unassigned"; 
	SSN = 999999999; 
};

Student::Student(string name_in, int SSN_in)//definition of constructor
{
	name = name_in;
	SSN = SSN_in;
}

int Student::display_ssn()
{
	return SSN;
}


string Student::display_name()
{
	return name;	
}

int main()
{
	//first object
	Student student1;//using default constructor
	//second object
	Student student2("John Doe", 123456789);

	

	cout << "Name for student1 is " << student1.display_name() << " and ssn is " << student1.display_ssn() << endl;
	cout << "Name for student2 is " << student2.display_name() << " and ssn is " << student2.display_ssn();
	
	cin.get();
	return 0;
}


Made in Visual Studio 2013. Works fine.
MarekG,

Thank you, for clearing things up for me.
Write an interactive C++ program that inputs a series of 12 temperatures from the user. It should write out on file "tempdata.dat" each temperature and the difference between the current temperature and the one preceding it. The difference is not output for the first temperature that is input. At the end of the program, the average temperature should be displayed for the use via cout. For example, given the following input data:
34.5 38.6 42.4 46.8 51.3 63.1 60.2 55.9 60.3 56.7 50.3 42.2

File tempdata.dat would contain:

34.5
38.6 4.1
42.4 3.8
46.8 4.4
51.3 4.5
63.1 11.8
60.2 -2.9
55.9 -4.3
60.3 4.4
56.7 -3.6
50.3 -6.4
42.2 -8.1


#include <iostream>
#include <fstream>

using namespace std;
int main()
{
float current_temp, prev_temp, avg;
float t1;
float t2;
float t3;
float t4;
float t5;
float t6;
float t7;
float t8;
float t9;
float t10;
float t11;
float t12;
ofstream tempdata;
ifstream intemp;

float dift1t2;
float dift2t3;
float dift3t4;
float dift4t5;
float dift5t6;
float dift6t7;
float dift7t8;
float dift8t9;
float dift9t10;
float dift10t11;
float dift11t12;
float tempAvg;

intemp.open("intemp.dat");
tempdata.open("tempdata.dat");

intemp >> t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7 >> t8 >> t9 >> t10 >> t11 >> t12;

dift1t2 = t1-t2;
dift2t3 = t2-t3;
dift3t4 = t3-t4;
dift4t5 = t4-t5;
dift5t6 = t5-t6;
dift6t7 = t6-t7;
dift7t8 = t7-t8;
dift8t9 = t8-t9;
dift9t10 = t9-t10;
dift10t11 = t10-t11;
dift11t12 = t11-t12;
tempAvg = (t1+t2+t3+t4+t5+t6+t7+t8+t9+t10+t11+t12)/12;

tempdata << t1 << ' ' << endl << t2 << ' ' << dift1t2 << endl << t3 << ' ' << dift2t3 << endl << t4 << ' ' << dift3t4 << endl << t5 << ' ' << dift4t5 << endl << t6 << ' ' << dift5t6 << endl << t7 << ' ' << dift6t7 << endl << t8 << ' ' << dift7t8 << endl << t9 << ' ' << dift8t9 << endl << t10 << ' ' << dift9t10 << endl << t11 << ' ' << dift10t11 << endl << t12 << ' ' << dift11t12;

cout << "The Average Temperature is " << tempAvg;

intemp.close();
tempdata.close();
return 0;
}
Can someone help me with this C++ code. I am new to this .
Write an interactive C++ program that inputs a series of 12 temperatures from the user. It should write out on file "tempdata.dat" each temperature and the difference between the current temperature and the one preceding it. The difference is not output for the first temperature that is input. At the end of the program, the average temperature should be displayed for the use via cout. For example, given the following input data:
34.5 38.6 42.4 46.8 51.3 63.1 60.2 55.9 60.3 56.7 50.3 42.2

File tempdata.dat would contain:

34.5
38.6 4.1
42.4 3.8
46.8 4.4
51.3 4.5
63.1 11.8
60.2 -2.9
55.9 -4.3
60.3 4.4
56.7 -3.6
50.3 -6.4
42.2 -8.1
@ncaver - Do not hijack someone else's thread.
You've already posted this twice.
http://www.cplusplus.com/forum/beginner/174335/
http://www.cplusplus.com/forum/general/174333/
what are you talking about ??
Topic archived. No new replies allowed.