#OOP C++ Assignment Help
77 messages · Page 1 of 1 (latest)
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.
Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.
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
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!
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
What do you have so far?
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
Bump
I have arrived home, I am going to post the whole code, and a variation that I was trying
```cpp
int main() {}
```
int main() {}
#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
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 );
You can also just print the highestAverage without converting it to string which would be the fastest and simplest method
I know, but the lecturer said to specifically use it for some dumbass reason
To see we can use it I guess
There are lots of opportunities where converting between data types would be useful and he/she gave you a really pointless one lol
He's 64 and never actually worked in dev just taught
😦
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
Are you using something older than C++11?
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
Go to Toolbar -> Settings -> Compiler
CodeBlocks is outdated, it’s sad they’re making you use it
btw
It’s all good
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
Will do and he did not say anything about that in compiler
so its saying cout error now
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
Nice!
Such a small thing to get working, but such joy hahahah
For this, if you only use if statements then when any of them are true the code inside will be run. If you use if and else if statements only one of them will run
Oh okay okay
so Elseif in my mind is better for this then
and honestly looks cleaner
I’ll have to look more closely at your code but probably
Here's an example of this
#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";
}
}
;compile
only if
a
b
c
if, else if, else
a
I understand
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
Didn’t you already have CAO method inside your class?
@idle quartz Has your question been resolved? If so, type !solved :)
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