problems with structure array

this is my assignment question:

Each student in the university takes a different number of courses, so the registrar has decided to use a linked list to store each student’s class schedule and an array of structs to represent the whole student body.

These data show that the first student (ID 1111) is taking section 1 of CIS120 for three credits and section 2 of HIS1001 for four credits; the second student is not enrolled; and so on. Write a class for this data structure. Provide operators for creating the original array, inserting a student’s initial class schedule, adding a course, and dropping a course. Write a menu driven program that uses the class.


this is what i have so far:

UniversityClass.h

#ifndef UNIVERSITYCLASS_h
#define UNIVERSITYCLASS_h

class University
{
private:
int size;
struct Student
{
int id;
struct ListNode
{
string course;
int section;
int credit;
ListNode *next;
};
ListNode *head;
};
Student data;
Student *cA;

public:
University();
~University();
void createArray();
void insertData();
void deleteData();
void addCourse();
void dropCourse();
void display();
};

int main();

#endif


MainUniversity.cpp

#include<iostream>
using namespace std;
#include"UniversityClass.h"

int main()
{
University Uni(2);
int choice;

cout<<"University Class Schedule Management"<<endl;
cout<<"------------------------------------"<<endl<<endl;
cout<<"You can perform the following:"<<endl<<endl;
cout<<"(1) Creating the Original Array"<<endl;
cout<<"(2) Inserting Student's Data"<<endl;
cout<<"(3) Deleting Student's Data"<<endl;
cout<<"(4) Adding a Course"<<endl;
cout<<"(5) Dropping a Course"<<endl;
cout<<"(6) Display the Class Schedule"<<endl;
cout<<"(7) Exit"<<endl<<endl;
cout<<"Please Enter Your Choice: ";
cin>>choice;

switch(choice)
{
case 1 : Uni.createArray(); break;
case 2 : Uni.insertData(); break;
case 3 : Uni.deleteData(); break;
case 4 : Uni.addCourse(); break;
case 5 : Uni.dropCourse(); break;
case 6 : Uni.display(); break;
case 7 : exit(1); break;
default:
{
cerr<<"Invalid input, please enter 1 to 7 to select a task to perform.\n"<<endl;
main();
}
}

return 0;
}


Universityfuncbody.cpp

#include<iostream>
using namespace std;
#include"UniversityClass.h"

University::University()
{
size = 0;
data.head = NULL;
cA = new Student[size];
}

University::~University()
{
delete [] cA;
}

void University::createArray()
{
cout<<"Enter the size of the array: ";
cin>>size;
cA = new Student[size];
main();
}

void University::insertData()
{
cout<<"Enter the Student ID: ";
cin>>cA[0].id;
main();
}

void University::deleteData()
{

}

void University::addCourse()
{

}

void University::dropCourse()
{

}

void University::display()
{
cout<<cA[0].id<<" "<<size<<endl;
}

the coding is actually not same with what the question ask

this is what i get:

user input: size = 1, id = 2

output is: id = weird number, size = 0


my question is where should i change to let the display show the ID that the user enter and also to let the size input from user to be use in each function.
High-five on not capitalizing "private" or "public"!

I'm sorry, however I couldn't understand your question. Are you asking what you should change to let the console show the ID that the user enters into the struct? Or...

-Albatross
yes, is what i should change to let the console show the ID that the user enters into the struct.
so, anyone can help???
If you want the console to echo what you put into it (sorry about the wait), then I'd recommend creating a whole new function to fetch and print that data. It has to be a part of your class, since the struct is private.

Does that help?

-Albatross
ya, this help, thanks
Topic archived. No new replies allowed.