#OOP C++ Assignment Help

77 messages · Page 1 of 1 (latest)

idle quartz
#

Hi guys I got my first object orientated programming assignment for c++ it is just generating 3 reports for grades in a console application. I'm just wondering can anyone help explain a few things. My lecturer just gives us a4 sheets and tells us to copy em without explaining any of it. Thank you in advance for any help!!

polar mulchBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

#
How to Ask a Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What to Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error)
    :trophy: Gold Standard: Minimal Reproducible Example
Where to Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C and C++ snippets
  • OnlineGDB for interaction, debugging
    :no_entry: Do not post screenshots, let alone photos of your screen!
onyx perch
#

We can’t help you with the entire assignment but if you explain the specific problems you’re having trouble with, it’s much easier to help

idle quartz
#

I can tell ye when I get home if that's okay! I am currently on the train and my laptop is dead

#

It's very basic stuff. Just struggling to understand certain parts. I don't have a programming brain yet

torn dune
#

Bump

idle quartz
#

I have arrived home, I am going to post the whole code, and a variation that I was trying

polar mulchBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
idle quartz
#
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const int numStudents = 6;
const int numSubjects = 6;

class Validation{
public:
   static bool verifyMark(int mark)
    {
    return mark >0 && mark <= 100;
    }
};

class Exam {
private:
    string students[numStudents] = {"Evan Ferguson", "Chiede Ogbene", "Adam Idah", "Megan Connolly", "Katie McCabe", "Robbie Brady"};
    string subjects[numSubjects] = {"OOP", "PPD", "Maths for IT", "Networks", "Game Design", "Mobile Tech"};

    int marks[numStudents][numSubjects] = {
        {50, 50, 50, 50, 50, 50},
        {60, 80, 75, 50, 60, 75},
        {80, 55, 65, 59, 70, 70},
        {60, 68, 75, 50, 60, 55},
        {60, 70, 70, 67, 70, 70},
        {90, 90, 90, 90, 90, 90}
    };
    string grades[numStudents][numSubjects];
    double caoPoints[numStudents][numSubjects];

public:
    ///Method to get Grade from Mark
    void get_grade(){
    for (int i =0; i<numStudents; ++i)
    {
        for (int j =0; j < numSubjects; ++j)
            {
            int mark = marks[i][j];

            ///Verify mark and assign Grades
            if(Validation::verifyMark(mark))
            {
                if (mark <50) grades[i][j] = "U";
                else if (mark < 65) grades[i][j] = "P";
                else if (mark < 80) grades [i][j] = "M";
                else grades[i][j] = "D";

            }
            else
        {
                grades[i][j] = "Invalid";
        }

    }
    }
    }
    ///Method to Calculate CAO Points from Grade
    void get_CAO_points(){
    for (int i = 0; i < numStudents; i++){
    for(int j =0; j <numSubjects; ++j)
        {
        string grade = grades[i][j];

        if (grade == "U") caoPoints[i][j] = 0.0;
        else if (grade == "P") caoPoints[i][j] = 16.67;
        else if (grade == "M") caoPoints[i][j] = 33.33;
        else if (grade == "D") caoPoints[i][j] = 50.0;

        }
    }
}

void print_report1_header(){
    cout <<"Rathmines College\nQQi Level 5 Marks%   CCP1 May 2024\n";
    cout << "Student name              OOP    PPD   MATHS    Networks  Games   Mobile Average\n";
    for(int i = 0; i <numStudents; i++){
        cout << setw(20) << students[i];
        double studentTotal = 0; /// Store the total for the student
        for (int j =0; j < numSubjects; ++j){
            cout <<setw(8) << marks [i][j];
            studentTotal += marks[i][j]; ///Add mark to total
            }
            double average = studentTotal / numSubjects; ///Get the Average
            cout << setw(10) << fixed << setprecision(2) << average << "\n"; ///Display Average
    }
}
    void display_best_student(){
    double highestAverage = 0.0;
    string bestStudent;

    for(int i = 0; i < numStudents; i++)
        {
        double studentTotal = 0.0;
        for(int j = 0; j< numSubjects; j++)
        {
            studentTotal += marks[i][j];
        }
        double average = studentTotal / numSubjects;
        if (average > highestAverage)
        {
            highestAverage = average;
            bestStudent = students[i];
        }
        string hAverage = to_string(highestAverage);
        cout<< "Best student: "<< bestStudent<< "Highest average: "<<hAverage;

    }

    cout << "End of Report 1\n\n";
    }







};

int main()
{
    System ("COLOR 80")
  Exam exam;
  exam.get_grade();
  exam.get_CAO_points();
  exam.print_report1_header();
  exam.display_best_student();
  return 0;
}

#

This is the iteration of code I made from my own learning

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

using namespace std;

class Exams
{
public:
    string get_grade(float mark);
    void print_report1();
private:
    string dm_grade;
    string dm_sub_name[4] = {"English", "Maths", "Spanish", "Music"};
    float dm_mark;
};

void Exams::print_report1()
{
    cout<<setw(30)<< "Rathmine College" <<endl;
    cout<<setw(30)<< "QQI Leve 5 Marks%" <<endl;

    cout<<setw(8)<< "Modules ";
    for(int c = 0; c<4; c++)
    {
        cout<<left<<setw(10)<< dm_sub_name[c];

    }
    cout<<left<<setw(10)<<"Average ";
    cout<< endl;
}
    string Exams::get_grade(float mark)
    {
        dm_mark = mark;
        if(dm_mark <=50)
        {
            dm_grade = "U";
        }
                if(dm_mark >=50 && dm_mark <65)
        {
            dm_grade = "P";
        }
                if(dm_mark >=65 && dm_mark <80)
        {
            dm_grade = "M";
        }
                if(dm_mark >=80)
        {
            dm_grade = "D";
        }
        return dm_grade;
    }

    int data[4][4] = {50,50,50,50,
                      50,50,60,80,
                      75,60,60,75,
                      50,50,50,50};

                      string student_name[4] = {"G Best", "R Burton", "K Harris", "K Starmer"};

                      main()
                      {
                          system("COLOR 84");
                          class Exams student[4];
                          for(int a=0;a<65;a++)
                          {
                              cout <<"_";
                          }
                          cout<< endl;
                          class Exams reports;
                          reports.print_report1();

                          for(int i=0;i<4;i++)
                          {
                              cout<<setw(15)<< student_name[i];
                              for(int j=0;j<4;j++)
                              {
                                  cout<<setw(10)<<reports.get_grade(data[i][j]);
                              }
                              cout<< endl;
                          }
                          return 0;
                      }

#

That is the a4 sheet he gave me for the generation of the table. I had to finish the code to display the table myself casue he conveniently fogot to put it in there

#

What I am wondering is in the first piece of code, I cannot for the life of me get to_string() function to work and display the best student and highest average

#

I am thinking about removing the method for displaying the best student and just putting it in without a method call

onyx perch
#

The to_string works

#

The problem is that it's printing the best student multiple times because you put this part of the code inside the outer for loop

#

If you want to get rid of the trailing zeros you can do

    string hAverage = to_string(highestAverage);
    hAverage.erase ( hAverage.find_last_not_of('0') + 1, std::string::npos );
    hAverage.erase ( hAverage.find_last_not_of('.') + 1, std::string::npos );
idle quartz
#

Ohhhhhhh

#

Okay

#

So it needs to be moved

onyx perch
#

You can also just print the highestAverage without converting it to string which would be the fastest and simplest method

idle quartz
#

I know, but the lecturer said to specifically use it for some dumbass reason

#

To see we can use it I guess

onyx perch
#

There are lots of opportunities where converting between data types would be useful and he/she gave you a really pointless one lol

idle quartz
#

He's 64 and never actually worked in dev just taught

onyx perch
#

😦

idle quartz
#

yuuuuup

#

gonna be relearning everything after this hahahaha

onyx perch
#

might be for the best

#

any other places you're confused about?

idle quartz
#

I am getting this errpr after moviing it out of the loop. If I just put it in main() would it work

#

which of the methods for get_grade is more efficient

#

all those ifs, or elseifs

#

okay moved it again and have a new error for cout

onyx perch
#

Are you using something older than C++11?

idle quartz
#

Possibly? This guy got us to install this off a usb. Where can I check in my compiler

#

I am using codeblocks and the build I have is from 2017

onyx perch
#

Go to Toolbar -> Settings -> Compiler

#

CodeBlocks is outdated, it’s sad they’re making you use it

#

btw

idle quartz
#

that sucks

#

Still cannot find this version, sorry if I am being annoying hahahah

onyx perch
#

It’s all good

idle quartz
onyx perch
#

I would do the check for 14 tbh unless your teacher said something else specifically

#

After checking it and clicking ok, try running your code again

idle quartz
#

Will do and he did not say anything about that in compiler

#

so its saying cout error now

onyx perch
#

You can’t return something in a void function and especially you can’t return two different things in the way you did no matter what type of function

idle quartz
#

Its working!!!!

#

ANd ye I forgot it was void

onyx perch
#

Nice!

idle quartz
#

Such a small thing to get working, but such joy hahahah

onyx perch
idle quartz
#

Oh okay okay

#

so Elseif in my mind is better for this then

#

and honestly looks cleaner

onyx perch
#

I’ll have to look more closely at your code but probably

onyx perch
#
#include <iostream>
#include <string>

int main(){
    
    std::cout << "only if" << "\n";
    int b = 2;
    if(b == 2) std::cout << 'a' << "\n";
    if(b == 2) std::cout << 'b' << "\n";
    if(b < 10) std::cout << 'c' << "\n";
    
    std::cout << "\n";
    std::cout << "if, else if, else" << "\n";
    int a = 1; 
    if(a == 1) std::cout << 'a' << "\n";
    else if(a == 1) std::cout << 'b' << "\n";
    else if (a < 10) std::cout << 'c' << "\n";
    else{
        std:: cout << 'd' << "\n";
    }
}
bitter moatBOT
#
Program Output
only if
a
b
c

if, else if, else
a
idle quartz
#

I understand

idle quartz
#

okay I have another question for this

#

basically

#

I need to calculate the total CAO points and display them under that heading. I am not sure should I just add a full mehod to calculate CAO points

onyx perch
#

Didn’t you already have CAO method inside your class?

idle quartz
#

All good

#

figured it out

polar mulchBOT
#

@idle quartz Has your question been resolved? If so, type !solved :)

idle quartz
#

Thanks for the help nou!

#

!solved

polar mulchBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity