I've long looked at this site for advice, but I'm stuck now. I have an idea of WHAT I need to do, but don't know exactly how to do it.
YES this is homework. NO I'm not asking for anyone to completely do it because I need to learn this stuff. YES I am asking for help and I'm not the brightest bulb so I need specifics...
Here's my problem:
1. Define the class Address that has 4 data members:
• streetAddress: a string of a maximum of 50 characters
• city: a string of a maximum of 30 characters
• state: a string of a maximum of 30 characters
• ZIP: integer.
In addition to the data members, the class has functions to “set” and “get” the
values of the data members as well as a function to display the contents of all the
data members.
a) Write the header file Address.h for this class. Your class definitions should
not allow any function outside the class to access the data members.
b) Write the implementation file Address.cpp which implements the member
functions of the Address class.
2. Define a class Student that has the following data members:
• studentName: a string of a maximum of 30 characters
• studentID: an integer that is unique for each student and is dynamically
created when a new Student object is created.
• studentAddress: an object of the Address class
• GPA: a floating number
In addition to the data members, the class has functions to “set” and “get” the
values of the data members as well as a function to display the contents of all the
data members.
a) Write the header file Student.h for this class. Your class definitions should not
allow any function outside the class to access the data members.
b) Write the implementation file Student.cpp which implements the member
functions of the Student class.
3. Develop a “Course Roster Application” that allows the user to:
• create a course roster of any number of students. (use dynamically
allocated array of objects)
• enter information for each student.
• display information about a given student.
• list all the students in the course.
• display some statistics about the students enrolled in the course.
The applications should start by displaying a menu that has the flowing options:
1. Input a new roster.
2. Display the information of a student.
3. List all students registered in the class.
4. Display statistics.
5. Exit.
•
The first option should:
o ask the user to enter the total number of students registered in the class
o ask the user to enter the information for the students one student at a
time. It should do the following for each student until the information
for all the students is entered:
create a Student object and automatically assign a new student
ID to the new student. (Use simple serial numbering sequence
that starts with 1 and is incremented every time a new student
is added.)
ask the user to input the following information for the student:
• student name
• street address
• city
• state
• ZIP
• GPA
o After the user inputs the above fields for one student, the program
should loop back to ask for the information of the next student until all
students have been entered in the roster.
•
The second option should:
o ask for the student ID then searches the roster for that student.
o If it is found then student information’s is displayed otherwise a
message should be displayed to indicate that the student is not
registered in the course.
•
The third option should list all the students in the roster. Display only the ID,
name, ZIP and the GPA.
•
The forth option will calculate and display the following:
o The average GPA of the students in the course.
o The lowest GPA.
o The highest GPA.
•
The fifth option ends the application.
Programming Guidelines:
•
The program should use dynamic memory allocation to create the roster.
•
Use the switch statement to implement the required menu.
•
Each menu option (other than the exit option) should be implemented as an
individual function.
•
When the user selects an option from the menu (other than the exit option), the
program should perform the selected task then display the menu again.
•
The program should end ONLY if the user selects the “Exit” option.
•
Make sure your program doesn’t have any memory leaks by releasing all the
dynamically created memory when it is no longer needed.
•
Submit only the source code of your program:
The header file for the Address class (Address.h)
o
The header file of the Student class (Student.h)
o
The implementation file for the Address class (Address.cpp)
o
o
The implementation file of the Student class (Student.cpp)
o
The source file for the application (Roster.cpp)
Here is my code so far...
STUDENT.H
#include <iostream>
using namespace std;
class Student
{
private:
char studentName[30];
int studentID; ///Figure this one out
//char studentAddress streetAddress();
float GPA;
public:
char getName();
int getID();
char getStreet();
float getGPA();
void setName(char*);
void setID(int);
char setStreet();
void setGPA(float);
//friend class Address; // friend of class Address
};
STUDENT.CPP
#include "Student.h"
using namespace std;
char Student::getName()
{
return studentName[30];
}
int Student::getID()
{
return studentID;
}
/*string Student::getStreet()
{
return 0;//just a test
}*/
float Student::getGPA()
{
return GPA;
}
void Student::setName(char *myName)
{
strcpy_s(studentName, myName);
}
void Student::setID(int ID)
{
for (int i = 0; i < ID; i++)
{
studentID = 1;
studentID++;
}
}
/*Student::setAddress()
{
return 0;//just a test
}*/
void Student::setGPA(float myGPA)
{
GPA = myGPA;
}
ADDRESS.H
#include <iostream>
using namespace std;
class Address
{
private:
char streetAddress[50];
char city[30];
char state[30];
int zip;
public:
char getStreet();
char getCity();
char getState();
int getZip();
void setStreet(char*);
void setCity(char*);
void setState(char*);
void setZip(int);
friend class Student;
};
ADDRESS.CCP
#include "Address.h"
using namespace std;
char Address::getStreet()
{
return streetAddress[50];
}
char Address::getCity()
{
return city[30];
}
char Address::getState()
{
return state[30];
}
int Address::getZip()
{
return zip;
}
void Address::setStreet(char * myStreet)
{
strcpy_s(streetAddress, myStreet);
}
void Address::setCity(char * myCity)
{
strcpy_s(city, myCity);
}
void Address::setState(char * myState)
{
strcpy_s(state, myState);
}
void Address::setZip(int myZip)
{
zip = myZip;
}
ROSTERAPP.CPP
//Course Roster Application
#include <iostream>
#include "Address.h"
#include "Student.h"
using namespace std;
int menu();
void enterNew(), displayStudent(), listStudents(), dispStats();
int main()
{
int choice;
do {
choice = menu(); //get selection
switch(choice) {
case 1: enterNew();
break;
case 2: displayStudent();
break;
case 3: listStudents();
break;
case 4: dispStats();
break;
case 5: break;
default: cout<<"Please try again.\n\n";
}
} while(choice !=5);
return 0;
}
int menu() //Menu which returns a user's selection.
{
int choice;
cout << "1. Input a new roster.\n";
cout << "2. Display the information of a student.\n";
cout << "3. List all students registered in the class.\n";
cout << "4. Display statistics.\n";
cout << "5. QUIT.\n";
cout << "\nChoose one: ";
cin >> choice;
return choice;
}
/*
int* a = NULL; // Pointer to int, initialize to nothing.
int n; // Size needed for array
cin >> n; // Read in the size
a = new int[n]; // Allocate n ints and save ptr in a.
for (int i=0; i<n; i++) {
a[i] = 0; // Initialize all elements to zero.
}
*/
void enterNew()
{
system("CLS");
int n;
cout << "Please enter the total number of students registered in the class: ";
cin >> n;
cout << "\nThanks!\n";
int *arr = new int[n];
Student *stu;
stu = new Student[n];
char *name;
name = new char[30];
cout << "\nPlease enter the information one student at a time... ";
//stu[0].setID(n);
for (int i = 0; i < n ; i++)
{
cout << "\nPlease enter the Student's Name: ";
cin >> name;
stu[i].setName(name);
}
for (int j = 0; j < n ; j++)
cout << "NAME: " << stu[j].getName() << endl; //THIS IS ALL WRONG...
delete [] arr;
delete [] stu;
arr = NULL;
stu = NULL;
}
void displayStudent()
{
cout << "This will display student info.\n\n";
}
void listStudents()
{
cout << "This will list all students in a class.\n\n";
}
void dispStats()
{
cout << "This will display average GPA, lowest GPA, and highest GPA.\n\n";
}
I have lots of commented stuff in there just to use as possible examples and several of which that don't work that I haven't gotten to, but as this is 35% of my grade and due in less than a week, I've gotten desperate... but not desperate enough to pay someone else to do my work! hahaha
What I was working on last was getting a user's input for a student's name, but it's just printing out "=" and so I've given up trying this by myself for the day...
Any help is welcome. Thanks!