Project System registration using vectors ??

hello ..

i'm new here and i'm working on a project " System Registration for Students for a university " ...i've already done everything that is required .. and after i finish each task i test it ...and the teacher has asked us to do a specific Main ...so that program would be like a menu to choose from...

here is my main
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
68
69
70
71
int validate_choice_menu(int &x)


int main()
{
	string studentName;

	int mn,dy,yr;

	int choice_menu;

	cout<<"=+=+=+=+=+ Welecome to the Student Registeration System +=+=+=+=+=+="<<endl;
	
do
{
	cout<<"-_-_- please choose to select the service you want to do -_-_-"<<endl;

	cout<<"[ 1 ] Add a Student."<<endl;
	cout<<"[ 2 ] Add a Course. "<<endl;
	cout<<"[ 3 ] Student +  Course. "<<endl;
	cout<<"[ 4 ] Course  +  Student. "<<endl;
	cout<<"[ 5 ] Course  -  Student."<<endl;
	cout<<"[ 6 ] ! Student."<<endl;
	cout<<"[ 7 ] Print Student Details. "<<endl;
	cout<<"[ 8 ] Print Course Details . "<<endl;
	cout<<"[ 9 ] Exit. "<<endl;


	cout<<"Enter your Choice : "<<endl;
        cin>>choice_menu;
	cout<<endl;
	choice_menu=validate_choice(choice_menu);
	
	switch(choice_menu)
	{
	case 1:
		cout<<"~--~_~--~ ADD NEW STUDENT INFORMAITON ~--~_~--~"<<endl;

		cout<<"**Please Enter Your Full Name:"<<endl; ;						
                getline(cin,studentName);
			
		cout<<"**Enter the Date of registetion for the course in ""Month/ Day / Year Format :-"<<endl;	
	
			cin>>mn>>dy>>yr;				
			
	break;

	case 2:
		
		break;
	}

}
	while(choice !=9);


return 0;
}


int validate_choice_menu(int &x)
	{
		while((x !=1)&&(x!=2)&&(x!=3)&&(x!=4)&&(x!=5)&&(x!=6)&&(x!=7)&&(x!=8)&&(x!=9))
			{
			cout<<" invalide value pleas reenter another choice"<<endl;
			cin>>x;
			}
				return x;
	}



option from 3-6 are overloading operator functions ...
the problem is i want to use a vector container so i can use it to store an object student in "case 1"???..also the same thing for "case 2" only it's in a different vector container ??


also the other part of my project is the same thing expect i inherited from the "base class Student " to a 2 Derived classes "full time student " & "part time student " ...when i tested them alone i used a polymorphic approach "creating a pointer from a base class and gave it the address of a derived object " and it worked fine ...but i couldn't do it while using the vector container and the menu ...

any ideas ??

if any one needs the full code i'll put it up ...


please help since i'm stuck here i tried reading about vectors but i couldn't grasp the concept of using it ...
Last edited on
the problem doesn't seem to be in the code you posted, so it might help more if you posted the other parts of it. And by the way...

1
2
3
4
5
6
7
8
9
int validate_choice_menu(int &x)
{
        while(!(x >= 1 && x <= 9))      // better way to write the condition
	{
		cout<<" invalide value pleas reenter another choice"<<endl;
		cin>>x;
	}
	return x;
}


or

1
2
3
4
5
6
7
8
9
int validate_choice_menu(int &x)
{
        while(x < 1 || x > 9)      // another better way to write the condition
	{
		cout<<" invalide value pleas reenter another choice"<<endl;
		cin>>x;
	}
	return x;
}
Last edited on
okay i'll post the program
Student.h
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

#ifndef STUDENT_H_
#define STUDENT_H_

#include"Date.h"
#include"Course.h"

#include <iostream>
#include <string>

using namespace std;

class Student
{
	private:

		static int SerialId;

		const int id;

		string name;

		int CurrentCredits;

		bool CanRegisterMore();

	    Date EnrolmentDate;

	public:

		Student (string studentName,const Date &);

		bool RegisterCourse(Course);

		void DropCourse(Course);

		void PrintDetails();

		friend class Course;
	
		Student& operator+(Course);

		bool operator!();

};
#endif /*STUDENT_H_*/ 


Student.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "Student.h"
#include"Date.h"

#include<iostream>
#include <string>

using namespace std;

// intialization for static Data Member "Serial ID"..
int Student::SerialId=1000000;						


// Constructor function will intialize Data Members..& the System will generats the Serial number automatically..

Student::Student (string studentName,const Date &enrolment):id( SerialId),EnrolmentDate(enrolment)	
{
		SerialId++;	

		name=studentName;

		CurrentCredits=0;
}

// Function " Can Register More " To Check for the number Credits & return "true" if the Credits is less than 10 
//& return "false" if the Credits is more the 10..

bool Student::CanRegisterMore()							
{
	if(CurrentCredits<10)
		{
			return true;
		}
	else
		{
			return false;
		}
}

// Function "Register Course" recives an object from main that carrys the "Course Credits",then it will Add the 
//"Course Creidts"to the "Student Current Cridets" if the result was less than or equel 10 then it stores it in the
// Data Member "Current Credits" of "Student Class" & return true..other wise it will display a message & return
//false..

bool Student::RegisterCourse(Course c)											
{
	if (CanRegisterMore())
		{
			if ((CurrentCredits + c.get_Credits())<=10) 
				{
					CurrentCredits= CurrentCredits+ c.get_Credits();

					cout<<"You Have Registered Sucssefuly"<<endl;

					cout<<endl;
		
					return true;
				}	
		 }

	else 
			{
				cout<<"You have reached the allowed number of Credits for this semester"<<endl;

				cout<<endl;
				
				return false;
			}
}

// Function "Drop Course" recives an object from main that carrys the "Course Credits".if "Students Current Credits" is
//less than the credits from the "course credits" then function dispalys a message,Other wise the function substract
//"course credits"from the"Students Current Credits" ... 

void Student::DropCourse(Course c)		
{
	if (CurrentCredits<c.get_Credits())
		{ 
			cout<<"You don't have enough Credits to drop from"<<endl;

			cout<<endl;
		}
	else
		{
			CurrentCredits=CurrentCredits - c.get_Credits();

			cout<<"You Have Dropped sucssefuly"<<endl;
			
			cout<<endl;
		}
			
}

// Function " Print Details" to print Student object information about the student " Name/Serial ID/Current Credits"...\

void Student::PrintDetails() 
{
	cout<<"** Yor Informations are:-"<<endl;

	cout<<endl;

	cout<<"1] Name: "<<name<<endl;

	cout<<"2] Serial ID : "<<SerialId<<endl;

	cout<<"3] Your Number Of Credits : "<<CurrentCredits<<endl;
	
	cout<<endl;

	cout<<"///////////////////////////////////////////////"<<endl;

	cout<<endl;
}


Student& Student::operator+(Course c0)
{
	 RegisterCourse(c0);

	return *this;
}

bool Student::operator!()
{
	if (CanRegisterMore())
	    {
			cout<<"You Have Registered Sucssefuly"<<endl;

			cout<<endl;
		
			return false;
		}	
		 
	else 
		{
				cout<<"You have reached the allowed number of Credits for this semester"<<endl;

				cout<<endl;
				
				return false;
		}
}


Course.h
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
#ifndef COURSE_H
#define COURSE_H

#include <iostream>
#include <string>

using namespace std;

class Course
{
	private:

		int Credits;

		string ID;

		static int Num_ID;

	public:

		Course(string,int);

		void set_Credits(int);

		int get_Credits();

		void Print();

		friend class Student;

		Course& operator+(Student);

		Course& operator-(Student);
		
	
};

#endif /*COURSE_H_*/ 


Course.cpp
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
#include"Course.h"
#include"Student.h"

#include <stdio.h>
#include <iostream>
#include <string>
#include<iomanip>

using namespace std;

int Course::Num_ID=200;										

// Constructor function will intialize Data Members..& the System will generats the Course ID number automatically..
Course::Course(string course_ID ,int ccredit)						
{
	 set_Credits(ccredit);

	 char buffer[10];

	 Num_ID++;

	// Converting Int to string..
	sprintf(buffer,"%d",Num_ID);							
	
	// Storing the Course ID after conervting ..
    ID=course_ID+buffer;									
}

void Course::set_Credits(int ccredit)
{
	Credits=ccredit;
}

int Course::get_Credits()
{
	return Credits;
}

//Function "Print" to print Course object Information's about Courses " Course ID / Credits "..

void Course::Print()										
{
	cout<<setw(10)<<"Course: "<<setw(5)<<"|"<<setw(15)<<"Credits:"<<endl;

	cout<<setw(8)<<ID<<setw(7)<<"|"<<setw(8)<<Credits<<" "<<"Hours."<<endl;

	cout<<"-----------------------------------";

	cout<<endl<<endl;

}

Course& Course::operator+(Student s0)
{
	s0.RegisterCourse(*this);

	return *this;
}

Course& Course::operator-(Student s0)
{
	
	s0.DropCourse(*this);

	return *this;
}

Date.h
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
#ifndef DATE_H
#define DATE_H
 
#include<iostream>
#include<string>
 
class Date
{
	private:

		 int month; 
		 
		 int day; 
		 
		 int year;

		// utility function to check if day is proper for month and year...
		 int checkDay( int ) const;	

 public:
	 	 Date( int = 1, int = 1, int = 2000 ); 
	 
		 void print() const;
	    
}; 

#endif /*DATE_H_*/ 

Date.cpp
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
#include "Date.h"

#include<iostream>
#include<string>

using namespace std;

 
Date::Date( int mn, int dy, int yr )
{
	// validate the month
   if ( mn > 0 && mn <= 12 )											
		 {
			month = mn;
		 }
   else
		{
			 // invalid month set to 1..
			 month = 1;		
			 cout << "Invalid month (" << mn << ") set to 1.\n";
	    }

			 year = yr; 

			 // validate the day by calling the utility function and assigne it to Data member day..
			 day = checkDay( dy );												
			 cout << endl;
} 


// print Date object in form month/day/year...

void Date::print() const												
{
	cout << "**You have registed in : "<<month << '/' << day << '/' << year<<"."<<endl<<endl;
} 
 
// utility function to confirm proper day value based on month and year, & handles leap years,too...	

int Date::checkDay( int testDay ) const								 															 
{
    static const int daysPerMonth[ 13 ] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
      
	 // determine whether testDay is valid for specified month..
   if ( testDay > 0 && testDay <= daysPerMonth[ month ] )	
		{
		  return testDay;
	    }

	 // February 29 check for leap year ..
   if ( month == 2 && testDay == 29 && ( year % 400 == 0 ||	( year % 4 == 0 && year % 100 != 0 ) ) )			
		 {
			    return testDay;
   
			    // invalid Day set to 1..
			    cout << "Invalid day (" << testDay << ") set to 1.\n";
   
				return 1; 
		 } 
}


and the required is
• Your program should be menu driven.
• Create two arrays (or vectors) one for Students and one for Courses ( if you use
arrays, their sizes must be at least 5).
• The menu should provide the following options.
1. Add a Student.
2. Add a Course.
3. Student + Course
4. Course + Student
5. Course - Student
6. ! Student
7. Print details of a Student.
8. Exit
• Of course for options 3-7 , you have to prompt the user for the student and/or course
objects that will be used in that operations. For simplicity, you can use the index to
determine which object will be used.


i hope you know what is going on ??...Also Thank you very much for the little Edit i appreciate it ....
your problem is probably the same kind as this one.

http://www.cplusplus.com/forum/general/1715/

There's an example there with a vector to a pointer to base classes and assigning derived classes to it, as well as the polymorphic approach you were talking about. I hope that helps ^_^

lol I can't figure out how to make that a link.
Last edited on
Topic archived. No new replies allowed.