Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
hi im having his result failed results any idea what i did wrong? thanks:)

here are my codes:


// for the main file

#include <iostream>
using std::cout;
using std::endl;

#include "GradeBook.h"

GradeBook::GradeBook (string name)
{
setCourseName (name);
}

void GradeBook::setCourseName( string name)
{
courseName = name;
}

string GradeBook::getCourseName()
{

return courseName;
}

void GradeBook::displayMessage()

{
cout << "Welcome to the grade book for \n" << getCourseName()
<< "!" << endl;

}





// for the class file
#include <string>

using std::string;

class GradeBook
{
public:

GradeBook (string);
void setCourseName( string);
string getCourseName();
void displayMessage();

private:

string courseName;
};
 

Attachments

  • failed.png
    failed.png
    105.3 KB · Views: 92
hi, can anyone tell what is this annoying error about and what should i do? thanks!!:)
 

Attachments

  • chapter4-error.png
    chapter4-error.png
    65.1 KB · Views: 98
Those double quotes look a bit strange. Not sure if you are using the correct character for double quotes or if it is just the font you are using. But the error message implies that the double quotes are wrong.

b e n

By the way, instead of listing all the methods/members of a namespace you want to use, you can pull the whole namespace in with the line

Code:
using namespace std ;
 
It looks OK to me?????

Are the double-quotes around the < and > generic double-quotes?
They look like they might be the directional ones, which wouldn't be valid in C/C++.

If you're not sure, try deleting and retyping them.

Edit: beat to the punch.
 
:Dyou were right guys its the double quotes, changed it and got it working:)


been trying to figure how to get the functions working.. such as name change.. and character parameters.. etc:confused:

would you mind checking this out:D


thanks again:)
 

Attachments

  • Archive.zip
    16.3 KB · Views: 53
Okay have had a quick look. Looks like you are missing a constructor:-

Code:
int main()
{

GradeBook gradeBook1 ("CSO1 Introduction to C++ Programming", "Mona Cherri");

This needs the following constructor:-

In gradeBook.h:-

Code:
public:
GradeBook( const & string, const & string ) ; // consructed with course and instructor name.

In gradeBook.cpp

Code:
GradeBook::GradeBook( const string & course_name, const string & instructor_name  )
   
   : courseName( course_name ), instructorName( instructor_name ), yesName( "" )

{
}

Your code is okay but it is best to initialise class members in the above way. Also, I've used references to const strings as the parameters. It's a good idea to pass by reference rather than by value whenever possible. This avoids unnecessary copies. The const bit is there to enforce the requirement that the constructor/method should not alter the value of the variable (which it could since it is passed as a parameter by reference).

Also, if you end up using lots of things in std and many files, you're going to get sick of typing using std::xxx, so just use

Code:
using namespace std ;

One final point, it's common practise in C++ to distinguish between class member variables and temporary variables in code. For example I would rename your Gradebook members like this:-

Code:
private:
string course_name_ ; // course name for this GradeBook
string instructor_name_ ;
string yes_name_ ;

This has a couple of benefits:- when you look at your code it's easy to check that you are modifying a member value (rather than a local variable), secondly, it avoids having to juggle parameter names in methods when you want to set a member value. Here's an example of what I mean:-

Code:
GradeBook::GradeBook( const string & course_name, const string & instructor_name  )
   
   : course_name_( course_name ), instructor_name_( instructor_name ), yes_name_( "" )

{
}

If you don't like using _ there are other popular schemes one of which is using an 'm' before the variable name, eg mCourseName, mInstructorName etc.


b e n
 
hi, can you please follow up on what i did? i cant seem to get rid of the errors:confused: thank you for you patience:D
 

Attachments

  • followUp.png
    followUp.png
    73.3 KB · Views: 66
It would be much more helpful if you copy that source code and paste it in here in CODE blocks.

Include your .h file as well.

-Lee
 
Hi

Looks to me as though gradebook.h is missing the declaration of the new constructor.

The other 3 errors are just typos, you're using name which is not one of the parameters passed to the constructor. But then again those 3 lines are redundant because course_name_, instructor_name_ and yes_name_ are all initialised anyway because they are in the initialisation list ( the initialisation list is the stuff after the : and before the opening {.

b e n
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.