how to do this program


You are required to build the course approval system . Currently, during the registration week academics manually check if a student is meeting prerequisites for a given course. Write a object oriented program in C++ to solve this problem. For simplicity assume there is no more than one prerequisite for any given course. Three sample files are given for you in Fig.1 to verify your program. Courses.txt shows courses with corresponding prerequisites (0 means a course is offered in both semesters 1 means that course is offered in semester 1 and 2 means that a course is offered in semester 2), CSstudents.txt shows list of courses passed by the students, Students.txt shows list of students at USP and Registration.txt shows list of students with current registration. Do not change the format (columns and first row) of the sample files so that your program can read any file of the same format. For any further clarification post your questions on Moodle.

Some rules apart from prerequisite for courses apply during registration:  A student can enrol in at most two courses per semester.  A student can only do courses at the same level i.e. if a student has passed all CS course than the student can do courses from upper level.

Currently its semester 2.



Requirements

1. This problem must be solved using the Object-Oriented programming paradigm. You need four classes namely student, course, registration and CSstudents.

2. Create a project in Dev C++ and write class definitions for the above mentioned classes (header files). 3. Implement the member functions of the classes you defined in part 2 above (c++ files).

4. Add a source file to your project, the main_driver.cpp.
The driver program should be able to do the following:  Create necessary arrays to store the records of the file. The arrays will be of type classes you have defined.  Read the data file for up to size of 100.  Create a menu for the user that can do the following: o Exit program o Display all students at USP o Display all Courses offered at USP o Display details of students (id, name, age, and phone) registered in a course entered by user. o Register a student into a course. This should also add detail in the necessary files and array. Note, registration has some rules apart from prerequisite of a course. o Display all registration o Display number of semesters a student will take to complete all CS courses. The user will provide an id number and the program should calculate the number of semesters left.  Except the first menu, all others should be implemented using functions of the main program.
Last edited on
Hello prasad1927,

Welcome to the forum.

I would start with seep 2 and design the classes that you will need. The input files will help in defining the variables you will need for each class.

Two questions. Do you know about "vectors" yet? And is there a way to download the input files or could you post at least a sample of these files?

You will find that this is not a homework site. You can get some guidance to get started with, but you need to do the work your self. Post the code you have written and ask for help when something is not working right. If you get any errors when you compile the code that you do not understand, post the whole error message so there is no confusion.

I find that it is better to break up the specs into smaller pieces and work on the small pieces instead of trying to do the whole program at once.

I would start with the classes and work on the member functions as needed. Next I would most likely work on opening the files and reading them followed be printing or displaying what was read. The display does not have to be accurate or what you would want in the end it is just to see is things are working right.

When I know what the input files actually look like it makes things easier to help you.

Hope that helps,

Andy
course Prereq Semester
cs111 NA 0
cs112 cs111 2
cs240 cs112 1
cs241 cs240 2
cs214 cs112 2
cs215 cs112 2
cs218 cs111 2
cs310 cs215 1
cs311 cs112 1
cs317 cs215 2
cs318 cs218 2
cs324 cs240 2
cs341 cs241 1


(courses.txt)
ID lname fname age phone
s111 Chand Kay 22 12345
s222 Dev Ron 19 12346
s333 Tom John 20 12456
s444 Timothy Jacob 22 12486

student.txt
registration.txt
student courses
s111 cs214
s222 cs112


csstudents.txt
student courses
s111 cs111
s111 cs112
s222 cs111
s333 cs111
s333 cs112
s333 cs214
s333 cs240
s444 cs111
s444 cs112
s444 cs214
s444 cs218
thank you for your guidance .. i have written my code till here.. i dont know if its correct or not but i have written it till here... i have done for displaying all students where i dont get the correct infor in my output screen

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include <string>

using namespace std;

//Function Prototypes
const int SIZE = 100;
void discard_line(ifstream &in);
void readFileCSstudents(string students_registered[],string units_enrolled[], int &num_of_students );
void displayCSstudents(string students_registered[],string units_enrolled[], int &num_of_students);
void readFileCourse(string courses_available[],string prereq_available[],float semester_available[],int & num_of_courses);
void displayCourse(string courses_available[],string prereq_available[],float semester_available[],int & num_of_courses);

int main()
{
char choice;
string students_registered[SIZE];
string units_enrolled[SIZE];
string courses_available[SIZE];
string prereq_available[SIZE];
float semester_available[SIZE] ;
int num_of_courses = 0;
int num_of_students= 0;
readFileCSstudents(students_registered,units_enrolled,num_of_students);

do
{
system ("CLS");
//the menu
cout <<"****************************************"<<endl;
cout <<"|\tChoose From The Menu Below: |"<<endl;
cout <<"|\tA. Display all students. |"<<endl;
cout <<"|\tB. Display all Courses. |"<<endl;
cout <<"|\tC. Display student details. |"<<endl;
cout <<"|\tD. Register a student. |"<<endl;
cout <<"|\tE. Display all registration. |"<<endl;
cout <<"|\tF. Display number of semesters.|"<<endl;
cout <<"|\tOr any other key to exit. |"<<endl;
cout <<"****************************************"<<endl;
cout <<"\nChoose an option: ";
cin >>choice;

if(choice == 'A' || choice == 'a')
{
//option for displaying students when the user chooses choice A or a
displayCSstudents(students_registered,units_enrolled,num_of_students);
}
}

while (choice == 'A' || choice == 'a' || choice =='B' || choice == 'b' || choice =='C' || choice == 'c' || choice =='D' || choice == 'd' || choice =='E' || choice == 'e' || choice =='F' || choice == 'f');
return 0;
}
//skips the first line in the file folder
void discard_line(ifstream &in){
char c;
do
in.get(c);
while (c!='\n');}

// function for reading CSsudent file
void readFileCSstudents(string students_registered[],string units_enrolled[], int &num_of_students )
{
ifstream CSstudent;
CSstudent.open ("CSstudents.txt",ios::in);
if (CSstudent.fail())
{
cout << "File was not found\n";
system ("PAUSE");
exit(1);
}
discard_line(CSstudent);
while (!CSstudent.eof()){
CSstudent >> students_registered[num_of_students];
CSstudent >> units_enrolled[num_of_students];
num_of_students++;
}
CSstudent.close();
}


//function for displaying the CSstudent
void displayCSstudents(string students_registered[],string units_enrolled[], int &num_of_students)


{
cout<< "Student\t"<< "\tCourses" <<endl;
for(int i = 0; i < num_of_students; i++){
cout << students_registered<<"\t";
cout << units_enrolled<<"\t";
cout << endl;
}
system("pause");

}


****************************************
| Choose From The Menu Below: |
| A. Display all students. |
| B. Display all Courses. |
| C. Display student details. |
| D. Register a student. |
| E. Display all registration. |
| F. Display number of semesters.|
| Or any other key to exit. |
****************************************

Choose an option: a
Student Courses
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
0x70f1a0 0x70f4c0
Press any key to continue . . .
output screen
Hello prasad1927,

Thank you. I will get started with what you have and see what happens.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.

Andy
Hello prasad1927,

Looking over the program. Some of it is OK, but is does not follow the requirements set for this program.

Your arrays are of type "string" and should be of a class type something like:CSstudents students_registered[SIZE]; based on using what you have right now although I might use different name.

I would suggest learning not to use the line using namespace std; as it WILL get you in trouble some day. You can do a search here to read what many people have posted in the past. This is also useful reading:
http://www.lonecpluspluscoder.com/2012/09/22/i-dont-want-to-see-another-using-namespace-xxx-in-a-header-file-ever-again/

Learning to qualify what is in different namespaces is easier to learn now than all at once when school is over and your first employer tells you not to use using namespace std; and you find tht you have no idea what to do.

In the function "readFileCSstudents" looping on "eof" is not a good idea. Usually you end up processing the last read twice. The more accepted way would be:
1
2
3
4
5
while (CSstudent >> students_registered[num_of_students])
{
	CSstudent >> units_enrolled[num_of_students];
	num_of_students++;
}

Even though this is better you are still reading the information into the wrong place.

Also you define ifstream CSstudent;. This is defined as an input stream, so in CSstudent.open("CSstudents.txt", ios::in); the "std::ios::in" is not needed. It is actually redundant.

The function "discard_line" would be easier as:
1
2
3
4
5
6
void discard_line(ifstream &in)
{
	std::string line;

	std::getline(in, line);
}

Actually you do not need the function just the "std::getline" statement.

Using system("pause"); is not something that everyone can use. It is specific to Windows. And using "system" anything could allow the program to be hacked. To put a pause you have several choices. For a timed pause:

std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
or you could use:

1
2
std::cout << "\n\n\n\n Press anykey to continue";
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires heder file <limits>. 

Where line 2 will wait for "enter" to be pressed. Line 1 is also useful in more than just here.

When everything is run together I like to do this just to make it easier to understand.

You are required to build the course approval system.

Currently, during the registration week academics manually check if a student is meeting prerequisites for a
given course.

Write a object oriented program in C++ to solve this problem.

For simplicity assume there is no more than one prerequisite for any given course.

Three sample files are given for you in Fig.1 to verify your program.

Courses.txt shows courses with corresponding prerequisites
(0 means a course is offered in both semesters
1 means that course is offered in semester 1 and
2 means that a course is offered in semester 2),

CSstudents.txt shows list of courses passed by the students,
Students.txt shows list of students at USP and
Registration.txt shows list of students with current registration.

Do not change the format (columns and first row) of the sample files so that your program can read any file of
the same format.

For any further clarification post your questions on Moodle.

Some rules apart from prerequisite for courses apply during registration:
∙ A student can enrol in at most two courses per semester.
∙ A student can only do courses at the same level i.e. if a student has passed all CS course than the
student can do courses from upper level.

Currently its semester 2.



Requirements

1. This problem must be solved using the Object-Oriented programming paradigm.

You need four classes namely student, course, registration and CSstudents.

2. Create a project in Dev C++ and write class definitions for the above mentioned classes (header files).

3. Implement the member functions of the classes you defined in part 2 above (c++ files).

4. Add a source file to your project, the main_driver.cpp.

The driver program should be able to do the following:
∙ Create necessary arrays to store the records of the file. The arrays will be of type classes you have
defined.
∙ Read the data file for up to size of 100.
∙ Create a menu for the user that can do the following:
∙ Exit program
∙ Display all students at USP
∙ Display all Courses offered at USP
∙ Display details of students (id, name, age, and phone) registered in a course entered by user.
∙ Register a student into a course. This should also add detail in the necessary files and array.
Note, registration has some rules apart from prerequisite of a course.
∙ Display all registration
∙ Display number of semesters a student will take to complete all CS courses.

The user will provide an id number and the program should calculate the number of semesters left.
∙ Except the first menu, all others should be implemented using functions of the main program.

Sorry some of my indenting did not come out well, but you will get the idea.

I will do some work on the program until I see what ou come up with.

Hope that helps,

Andy
Topic archived. No new replies allowed.