Results 1 to 6 of 6

Thread: Need suggestions on approaching

  1. #1
    Join Date
    Sep 2005
    Posts
    2,394
    Rep Power
    0

    Default Need suggestions on approaching

    Can ya'll give some suggested solutions for the implementation of this question. Would deeply appreciate it.

    Create a Person class that contains Firstname, Lastname, DOB, address, telephone # and a virtual show function.

    Create a Student class that inherits from the Person class and adds StudentId, feespaid and Courses (array object of Course class). A student can register for a maximum of 6 courses and a minimum of 3. The show function calls calculatetotalfees that calculates and outputs the total fees for the student. It should also output the total fees paid and the amount due. Overload the plus operator within the student class such that it increases the fees paid variable by an amount specified in the parameter.

    Create a class named Course that contains Coursename, Coursecode, Number of Credits and Cost per Credit which is a static variable.

    Create a function called calculatetotalfees that calculates the fees for a student by adding the cost of each course that a student takes. The cost of each course can be found by multiplying the number of credits of each course by the cost per credit.

    Create a main that creates 10 student objects as well as 15 course objects. The software should use a loop to call the show function of each student object.
    To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton

  2. #2
    Join Date
    Feb 2012
    Posts
    295
    Rep Power
    0

    Default

    why not start out by writing your classes and worry about what comes in main() later
    im still learning c++ so this might be wrong
    Code:
    //example Person class
    #include <string>
    
    Class person{
    Public:
        Virtual show();
        String Firstname;
        String Lastname;
    Private:
        Int DOB;
        String Address;
        Int tel;
     
    };

  3. #3
    Join Date
    Sep 2005
    Posts
    2,394
    Rep Power
    0

    Default

    Person.h
    Code:
    #ifndef PERSON_H
    #define	PERSON_H
    
    #include <string> 
    using namespace std;
    
    class Person {
    
    public:
        Person();
        ~Person();
        virtual void show();
        virtual void setData(string, string, string, string, int);
        
    
    
    protected:
        string FirstName, LastName, DOB, Address, Tel;    
    };
    
    #endif	/* PERSON_H */
    Person.cpp
    Code:
    #include "Person.h"
    
    Person::Person() {
    }
    
    Person::~Person() {
    }
    
    void Person::show(){
    }
    
    void Person::setData(string firstname, string lastname, string dob, string address, int tel)
    
       {
          FirstName = firstname;
          LastName = lastname;
          DOB = dob;
          Address = address;
          Tel = tel;
       }
    Course.h
    Code:
    #ifndef COURSE_H
    #define	COURSE_H
    
    #include <string>
    using namespace std;
    
    class Course {
    friend class Student;
    public:
        Course();
        Course(string, string, int);
        virtual ~Course();
        void getCourse();
    private:
        string CourseName, CourseCode;
        int Credit;
        static float CostPerCredit;
    };
    
    
    #endif	/* COURSE_H */
    Course.cpp
    Code:
    #include <iostream>
    #include "Course.h"
    
    using namespace std;
    
    Course::Course() {
    }
    
    Course::Course(string Cname, string Ccode, int Cred):CourseName(Cname),
        CourseCode(Ccode), Credit(Cred) 
    {   
    }
    
    Course::~Course() {
    }
    
    void Course::getCourse(){
        cout << CourseName << "\t" << CourseCode << "\t" << Credit << "\t" << CostPerCredit << endl;
        cin.get();
    }
    
    float Course::CostPerCredit = 1000.00;
    Student.h
    Code:
    #ifndef STUDENT_H
    #define	STUDENT_H
    
    #include "Person.h"
    #include "Course.h"
    #include <string>
    using namespace std;
    
    class Student: public Person {
    public:
        Student();
        virtual ~Student();
        void show();
        void Register();
        void setBio(string, string, string, string, int);
        void setCourses(int);
        float CalculateTotalFees();
            
    private:
        string StudentID; 
        float FeesPaid, FeesBalance,Inc;
        Course Courses[];
    };
    
    #endif	/* STUDENT_H */
    Student.cpp
    Code:
    #include <iostream>
    #include "Student.h"
    
    using namespace std;
    
    
    Student::Student() {
    }
    
    Student::~Student() {
    }
    
    void Student::Register(){
        //Store registration data
       
        string sid, fn, ln, db, ad, ph;
        int i;
        
        cout << "Enter Student ID: \t";
        cin >> sid;
        cout << endl << "Enter First Name: \t";
        cin >> fn;
        cout << endl << "Enter Surname: \t";
        cin >> ln;
        cout << endl << "Enter DOB: \t";
        cin >> db;
        cout << endl << "Enter Address: \t";
        getline(cin, ad);
        cout << endl << "Enter Phone #: \t";
        cin >> ph;
        
        setBio(sid, fn, ln, db, ad, ph);
        
        cout << endl << "How many courses do you wish to do?";
        cin >> i; 
                       
        while(i < 3 || i > 6){
            cout<<"You must enter at least 3 but no more than 6." << endl << "How many courses do you wish to do?";
            cin >> i;   
        }
        
        cout << "Available Courses: " << endl <<
                "Code \t\t" << "Course" <<
                "1 \t\t" << "Business Communication" <<
                "2 \t\t" << "Business Systems" <<
                "3 \t\t" << "Data Communication" << endl << endl;
        
        if(i >= 3 && i <= 6){
            setCourses(i);
        }
    
    }
    
    void Student::show(){
       //Print student data 
    }
        
    void Student::setBio(string ID, string fname, string lname, string dob, string addr, int tel){
        StudentID = ID;
        FirstName = fname;
        LastName = lname;
        DOB = dob;
        Address = addr;
        Tel = tel;
    }
    
    void Student::setCourses(int i){
        int coursetype; 
        for(count = 0; count <= i; count++){
            cout<<"\nenter course you wish to register for: ";
            cin>>coursetype;
            
            switch(coursetype){
                case 1:
                    Courses[1] = Course.BusComm;
            }
               
    }
    }
    
    float Student::CalculateTotalFees(){
        //Calculate fees
        
    }
    main.cpp
    Code:
    #include <iostream>
    #include "Student.h"
    #include "Course.h"
    
    using namespace std;
    
    /*
     * 
     */
    
    void header();
    
    int main(int argc, char** argv) {
        
        Course BusComm("Business Communication", "BSCOM03", 3),
               BusSys("Business Systems", "BSSYS01", 3), 
               DataComm("Data Communication", "DTCM01", 3), 
               Network("Networking", "NETK01", 3), 
               Calculus("Calculus", "MATH03", 4), 
               Stats("Statistics", "MATH02", 3), 
               Algorithm("Algorithm Development", "PROG01", 3), 
               WebApp("Web Applications", "WEBP01", 3), 
               Comm1("Communication 1", "BSCOM0103", 3), 
               Comm2("Communication 2", "BSCOM02", 3), 
               VB("Visual Basic", "PROG03", 3), 
               DataStruct("Data Structures", "DTSTR01", 3),
               Cplus("C Plus Plus", "PROG02", 3), 
               Econ("Micro Economics", "ECON01", 3), 
               DataBase("Data Management", "DBMS01", 4);
       
               
       Student Ray, Dennis, Francine, Jessica, Nadine, Sandie, Neil, Chev, Jason, John;
       
       header();
       
       Ray.Register();
       
        
       return 0;
    }
    
    void header(){
        cout << "##################################################################" <<
                "##################################################################" <<
                "##                                                              ##" <<
                "##       Welcome to XLCR Course Registration System (XCRS)      ##" <<
                "##                                                              ##" <<
                "##################################################################" << 
                "##################################################################" << endl << endl;
    }
    Code is incomplete but its where am at so far and trying to figure out loads a stuff.
    Last edited by lovepython; Dec 8, 2012 at 08:21 AM.
    To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton

  4. #4
    Join Date
    Sep 2005
    Posts
    2,394
    Rep Power
    0

    Default

    Am here now trying to figure out how i can access the Course objects in main from the setCourses function in the Student class...sigh
    To find what you seek in the road of life, the best proverb of all is that which says: "Leave no stone unturned." Edward Bulwer Lytton

  5. #5
    Join Date
    Jul 2002
    Posts
    1,388
    Rep Power
    0

    Default

    Quote Originally Posted by lovepython View Post
    Am here now trying to figure out how i can access the Course objects in main from the setCourses function in the Student class...sigh
    I found nothing on the interwebs on using class functions from other cpp files. Does extern work?
    Code:
    #ifndef STUDENT_H
    #define	STUDENT_H
    
    #include "person.h"
    #include "course.h"
    #include <string>
    using namespace std;
    
    extern class Student: public Person {
    public:
        Student();
        virtual ~Student();
        void show();
        void Register();
        void setBio(string, string, string, string, int);
        void setCourses(int);
        float CalculateTotalFees();
            
    private:
        string StudentID; 
        float FeesPaid, FeesBalance,Inc;
        Course Courses[];
    };
    
    #endif	/* STUDENT_H */
    I get this error: "a storage class can only be specified for objects and functions student.h /course_proj line 23 C/C++ Problem"
    Sharing is caring? Then what if I care too much? A precarious situation, indeed...
    http://ip-check.org/ip-check.png

  6. #6
    Join Date
    Dec 2010
    Posts
    256
    Rep Power
    0

    Default

    StudentEnrollment.h:
    #ifndef STUDENTENROLLMENT_H
    #define STUDENTENROLLMENT_H

    # include <iostream>
    # include <string>

    using namespace std;

    class Roster {

    private:

    string courseName;
    string courseCode;
    string courseCredits;
    string professorName;

    public:

    void setCourseName ( string );
    void setCourseCode ( string );
    void setCourseCredits ( string );
    void setProfessorName ( string );

    string getCourseName();
    string getCourseCode();
    string getCourseCredits();
    string getProfessorName();

    Roster ();

    };

    #endif;

    StudentEnrollment.cpp:
    #include <iostream>
    #include <string>
    #include "StudentEnrollment.h"

    using namespace std;

    // Roster class implementation

    Roster::Roster () {

    courseName = "";
    courseCode = "";
    courseCredits = "";
    professorName = "";


    }


    void Roster::setCourseName ( string cn ) {
    courseName = cn;
    }

    void Roster::setCourseCode ( string c ) {
    courseCode = c;
    }

    void Roster::setCourseCredits ( string cc ) {
    courseCredits = cc;
    }

    void Roster::setProfessorName ( string pn ) {
    professorName = pn;
    }

    string Roster::getCourseName() {
    return courseName;
    }

    string Roster::getCourseCode() {
    return courseCode;
    }

    string Roster::getCourseCredits() {
    return courseCredits;
    }

    string Roster::getProfessorName() {
    return professorName;
    }

    main.cpp:
    #include <iostream>
    #include <string>
    #include "StudentEnrollment.h"

    using namespace std;

    int main (int argc, char * const argv[]) {

    int number_of_rosters = 0;

    string course, code, credits, name;

    cout << "Enter the number of rosters you would like to create: ";
    cin >> number_of_rosters;
    cin.ignore(100, '\n');


    Roster roster[number_of_rosters];

    for ( int i = 0; i < number_of_rosters; i++){
    cout << "Enter course name: ";
    getline(cin,course);
    roster[i].setCourseName(course);

    cout << "Enter course code; ";
    getline(cin, code);
    roster[i].setCourseCode(code);

    cout << "Enter course credits: ";
    getline(cin, credits);
    roster[i].setCourseCredits(credits);

    cout << "Enter professor name: ";
    getline(cin, name);
    roster[i].setProfessorName(name);

    cout << "Next course..." << endl;
    }

    cout << endl;

    for ( int i = 0; i < number_of_rosters; i++){
    cout << roster[i].getCourseName() << endl;
    cout << roster[i].getCourseCode() << endl;
    cout << roster[i].getCourseCredits() << endl;
    cout << roster[i].getProfessorName() << endl;
    cout << endl;
    }

    return 0;
    }













    Have you giving linklists any thought? – samy.vilar Aug 23 '12 at 18:11


    Was this post useful to you?
    Dip,Bsc,CCNA,CCSP,MCP.. Up next MCSA WINDOWS 8, CCNA SECURITY,CCNP SWITCH,
    CCNA SEEKING AN OPPORTUNITY
    Theres no Friend Like Google..........

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •