By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

Some part i havent learnd, so I cant solve it

P: 1
Exercise :

Given the diagram below. Transform the diagram into C++ program.

Class Grade
Private members :char letter;float score;
Public Members :void SetScore( float );float GetScore( );char CalculateGrade ( );


Class Test
Private members :int NumberOfQuestion;float PointsEach;int NumMiss;
Public Members :Test( int, int );




Grade is given using the table below :
> 89 A
> 75 B
> 60 C
< 50 F

Sample Program Output :
How many questions are on the test? 20 [Enter]
How many questions did the student miss? 3 [Enter]
The score is 85
The grade is B
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
class grade
{
private:
char letter;
float score;
public:
void setscoce (float);
float getscore ();
char calculategrade();
};

save as 11.h

#include<iostream.h>
#include"c:\borlandc\bin\11.h"

void grade::setscore(float n)
{
score = n;
}
float grade::getscore();
{
return score;
}
char grade::calculategrade()
{
if (score>89)
letter="A";
else if (score>75)
letter = "B";
else if (score>60)
letter = "C";
else if (score>50)
letter = "F";

return grade;
};

save as 11.cpp

#include"c:\borlandc\bin\11.cpp"

class test:public grade
{
private:
int numberofquestion;
float pointseach;
int nummiss;
public:
test(int, int);
};
================================================== ==============================
This is what I done so far, and the 3rd last time I cant solve it coz teacher havent tought us about it :S
Jun 12 '06 #1
Share this Question
Share on Google+
1 Reply


Banfa
Expert Mod 5K+
P: 8,916
save as 11.h
This is very bad form try using meaningful names at all times for file names, class names, function names and variable names. For instance grade.h

#include"c:\borlandc\bin\11.h"
What are you doing saving the file in the c:\borlandc\bin directory. This is the directory that your IDE uses to keep it's binary (executable) files in. You will make it very messy if you put all your source files in there as well. Put your source files in a different directory made specially for the program you are writing.

char grade::calculategrade()
{
if (score>89)
letter="A";
else if (score>75)
letter = "B";
else if (score>60)
letter = "C";
else if (score>50)
letter = "F";

return grade;
};
This wont work (probably wont compile either) grade is of type char (*)(void), i.e. is a pointer to a function taking no parameters and returning char. You need to return type char, I suspect you meant return letter;

save as 11.cpp
See comment above about using sensible meaningful file names.

#include"c:\borlandc\bin\11.cpp"
Including c code into headers is asking for trouble at the link stage with multiply defined symbols. You probably meant to include the header which would be reasonable.

and the 3rd last time I cant solve it coz teacher havent tought us about it :S
Sorry the first part of this does not make sense, what hasn't your teacher taught you?
Jun 13 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.