Thread: Need help on this.

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    6

    Need help on this.

    Answer for C++ coding exercise? - Yahoo! Answers

    To get a better understanding of my problem, look at the above post.


    Ok so I am having a problem similar to this guy that I saw trying to find someone to give him the answer (2 years ago).

    I am not asking for the exact answer, but hints on how to move forward would help.
    Code:
    Pseudocode for the GetStudentData:
                Declare variables
     
                Using a for loop input the data for each student
                            Dynamically create a Student object and assign it's address to the array            
                            Using a for loop input the data for each course
                                        Dynamically create a Course object
                                        Call the AddCourse method in the Student class passing it
                                                    the index position where you want it to go and the address of 
                                                    the newly created Course object
                                                 End-For
                            Sort the courses for the student 
                End-For
     
    Pseudocode for the PrintGradeReports:
                Using a for loop
                            Call the Print method for each student
                End-For
     
    Pseudocode for the Print method in the Student class
                Output the student's information
                For each course the student is taking
                            Call the Print method in the Course class
                            If the tuition is paid
                                        Output the course grade
                            Else
                                        Output ***
                            End-If
                End-For
                Output the number of credit hours
                If the tuition has been paid 
                            Calculate the GPA and output it
                Else
                            Output the message and the amount of tuition the student owes
                End-If
    I know most of my code is incomplete and I have been looking at an book as an example, but then I realized it's not really a good example...because my teacher is saying to do something different.

    I do not really understand the bolded part of the pseudo-code that he has given me. Also, it doesn't help that I'm going to a school where all the information is rushed and I only go two days out of the week. Any kind of help would suffice. I will be on all night today trying to do this and will keep updating until I finish.


    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    
    using namespace std;
    
    class Person
    {
    private:
        string mFirstName;
        string mLastName;
    public:
        string getFirstName()
        {
            return mFirstName;
        }
    
        string getLastName()
        {
            return mLastName;
        }
    };
    
    class Course
    {
    private:
        string mCourseName;
        string mCourseNumber;
        int mCourseCredit;
        char mCourseGrade;
    public:
        void Print()
        {
    
        }
    
        string getCourseName()
        {
            return mCourseName;
        }
    
        string getCourseNumber()
        {
            return mCourseNumber;
        }
    
        int getCourseCredit()
        {
            return mCourseCredit;
        }
    
        char getCourseGrade()
        {
            return mCourseGrade;
        }
    };
    
    class Student : public Person
    {
    private:
        string mID;
        int mNumCourses;
        bool mlsTuitionPaid;
        Course *mCoursesEnrolled[6];
    public:
        void SortCourses()
        {
        }
    
        string getID()
        {
            return mID;
        }
    
        void Print()
        {
            outfile << "Student Name: " << stPointAr[i]->getFirstName();
        }
    
        int GetHoursEnrolled()
        {
            return mHoursEnrolled;
        }
    
        double GetGPA()
        {
            int i;
            double sum = 0;
    
            for (i = 0; i < mNumCourses; i++)
            {
                switch (Course::getCourseGrade)
                {
                case 'A':
                    sum += mCoursesEnrolled[i]->getCourseCredit() * 4;
                    break;
                case 'B':
                    sum += mCoursesEnrolled[i]->getCourseCredit() * 3;
                    break;
                case 'C':
                    sum += mCoursesEnrolled[i]->getCourseCredit() * 2;
                    break;
                case 'D':
                    sum += mCoursesEnrolled[i]->getCourseCredit() * 1;
                    break;
                case 'F':
                    sum += mCoursesEnrolled[i]->getCourseCredit() * 0;
                    break;
                default:
                    cout << "Error - Invalid Course Grade." << endl;
                }
            }
            return sum/GetHoursEnrolled();
        }
    
        double getBillingAmount()
        {
            TuitionRate
        }
    };
    
    const int MAX_STUDENTS = 10;
    void GetStudentData();
    void PrintGradeReports();
    
    void main()
    {
        ifstream infile;
        ofstream outfile;
        int numRegSt; 
        double TuitionRate;
    
        infile.open("InClass Data.txt");
    
        if(!infile)
        {
            cout << "Error - input file not found." << endl;
            return;
        }
    
        outfile.open("OutClass Data.txt");
    
        infile >> numRegSt;
        infile >> TuitionRate;
    
        GetStudentData();
        PrintGradeReports();
    
        system("Pause");
    }
    
    
    void GetStudentData()
    {
        ifstream infile;
        Student *stPointAr[MAX_STUDENTS];
        int numStudents;
    
    
            for(int i = 0; i < numStudents; i++)
            {
                infile >> stPointAr[i]->getFirstName() 
                    >> stPointAr[i]->getLastName()
                    >> stPointAr[i]->getID()
                    >> stPointAr[i]->mlsTuitionPaid;
    
                if(isPaid == 'Y')
                    mlsTuitionPaid = true;
                else
                    mlsTuitionPaid = false;
    
                infile >> stPointAr[i]->mNumCourses;
    
                for (int j = 0; j < mNumCourses; j++)
                {
                    infile >> 
                }
            }
    }
    
    void PrintGradePoints()
    {
        for(int i = 0; i < numStudents; i++)
            Student::stPointAr[i]->print();
    }

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    Cmon guys any help would be appreciated ...

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What exactly is troubling you concerning the bolded part of the requirements/pseudocode?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    lol all of it XD. Well I don't think I am doing it right. My brain isn't working really well or I'm just plain stupid. I still feel like a newbie going into this.

    So i guess I'll take baby steps:

    Dynamically create a Student object and assign it's address to the array <-

    This part is telling me

    Student* whatever = new Student; <- is that right?


    Using a for loop input the data for each course <-


    Then that ... I just don't even know. is it asking me to input all the data from Course class, or was I doing it right in my code?

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by AbrAlvarez
    This part is telling me

    Student* whatever = new Student; <- is that right?
    Not quite: that would dynamically create a Student object, but you are assigning its address to a pointer, not an array. Thus, you would need an array of pointers, or better yet a std::vector or std::array of (smart) pointers.

    Quote Originally Posted by AbrAlvarez
    Then that ... I just don't even know. is it asking me to input all the data from Course class, or was I doing it right in my code?
    It sounds like all the data for each Course object that should be associated with the Student object. It is not 100% sensible since courses probably should be created separately from students, but that it what I see.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    Now I'm even more confused ... well I'm getting nowhere today so, I'm gonna call it a night (so much for staying up). The sleepiness hit me harder than I thought, I'll just ask my professor later on today when I wake up. Thanks for the help though.

Popular pages Recent additions subscribe to a feed

Tags for this Thread