I have an assignment a C++ assignment and here is my code so far;

#include <iostream.h>
#include <stdlib.h>
#include <cstring>
#include <cctype>

class Student
char Name[80];
long SSN ;

Student (char, long);

void setSSN (int SSN);
void setName (int Name);

int getSSN (long);
int getName (char);


Student::Student (char Name, long SSN)
char Name [80] = "unassigned";
long SSN = 999999999;

int Student::getName()
return Name;

int Student::getSSN()
return SSN;

void Student::setName(int name)
int name = "John Doe"

void Student::setSSN(int ssn)
int ssn = 123456789

void printName(Student *nameprint);
void updateName(Student *nameprint);
void printSSN(Student *ssnprint);
void updateSSN(Student *ssnprint);

int main()
Student myStudent;
Student mySSN;
return 0;

void printName(Student *dName)
cout << dName->getName( ) << endl;

void printSSN(Student *dSsn)
cout << dSsn->getSSN( ) << endl;

void updateName(Student *nameprint)
namePrint->setName(int name);


void updateSSN(Student *ssnprint)
namePrint->setSSN(int ssn);


I need it to do this:

Create a class named Student. The class should consist of the following private member variables: social security number and name (last, first or first, last?). The social security number (SSN) should be a long integer. The name variable should be a character array of 80 characters. (This means use a C-style string only. You may not use a string/String class anywhere.)

Create the following class member functions: setSSN, getSSN, setName, getName. Each of the functions should be public.

The setSSN function should accept 1 argument and update the the social security number member variable. Do not allow the the social security number to be set to zero or less than zero. The getSSN should return the class SSN.

The setName member function should accept one string argument. Use the argument to update the name class member variable. Do not update the class variable for name if the argument has a length of 0. (This indicates the name in the argument is "empty".) The getName method should return the class value for name.

Create a default constructor. (This constructor will accept no arguments.) Use the default constructor to initialize the social security number to 999999999 and the name to "unassigned".

Make sure all your methods are defined in the implementation section of the class. Do not use any inline member functions.

Do not print from the Student class. Instead retrieve the data in the main() function and print from main.

Create a main function. In the main method create two Student objects. Use the appropriate get functions to print all the values of all the member variables for the first Student object. For the second object, use the set methods to change the student name to John Doe and the social security number to 123456789. Use the appropriate get functions to print all the values of all the member variables for the second Student object.

I am having MANY issues, what am I doing wrong??

8 Years
Discussion Span
Last Post by jeffcruz

it sounds like you're supposed to create 2 separate classes (Student) and then a main class to run it all from...?
(Do not print from the Student class. Instead retrieve the data in the main() function and print from main.)

sounds like you need Student to be a 'standalone' class that does not have a void main() in it.

But then your code has:
Student student
Student ssn

ssn is not a student - that reads to me like you don't really understand that the Class Student is an encapsulation of student info (containing ssn) and should be (for example) student1 and student2 - not that it has a direct effect on the code, just the readability.

I'm working right now so don't have time to go through the code fully - I just came here to find a code sample I needed. I'll see if I can go through it after hours if you're still having issues.



I appreciate the help, and yeah I'm kind of lost. My teacher is mediocre at best and I'm basically left to teaching this to myself. I took this class thinking it would be an easy elective, but coupled with Calculus, Statistics and English II, this class is taking away lots of time I need for my other classes, causing all my other classes' grade's to suffer. I wish I had dropped this class when I had the chance >.< .

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.