Hi guys! I'm new in c++ so i really need your help. I have to do a project Student Course Registration. I have to do a program where students can insert their id name and course. I have to use classes in c++

Recommended Answers

All 4 Replies

I have this code can you help me fix the errors please

main

#include <iostream>
#include "Course.h"
#include "Date.h"
#include "Student.h"

using namespace std;


int validate_choice_menu(int &x)
{
        while(x < 1 || x > 9)
    {
        cout<<" invalide value pleas reenter another choice"<<endl;
        cin>>x;
    }
    return 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_menu(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_menu !=9);


return 0;
}


int validatechoice_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;
    }

Student.h

#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

#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

#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

#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

#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

#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; 
         } 
}

To OP. OK you dumped how many hundred lines of code and ask to fix the errors but didn't list the errors.

Ask yourself if others will have the same compiler, settings, IDE and more. Try sharing the first error and see if others can point out why.

PS. Why does your code look so much like http://www.cplusplus.com/forum/beginner/6840/ ?
If you re-use code, cite source, etc.

Don't expect us to flea out ALL "your" code.
Be specific on this line is this error message, on that line I have that problem.
Don't tell us you have errors or it does not work.
We know it doesn't, just be specific with your question if you hope to get an answer!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.