Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 09-08-2008, 03:31 PM   #1 (permalink)
The.Merridian
Recruit
 
Join Date: Aug 2008
Posts: 6
The.Merridian is on a distinguished road
Angry Classes and Object oriented stuff

I'm going bonkers and I can't figure out what the heck I'm doing wrong. :\

I have to modify a program from the text book so that it's output looks something like this:

Instructor name: John Doe
New instructor name: Professor Xavier

Welcome to the grade book for Intro to C++ programming!

I can get it to run, except when I try to create an object in the main function.

Code:
//function main
#include <iostream>
#include <string>
using namespace std;

#include "GradeBook.h"

int main()
{
    GradeBook myGradeBook;
   
    cout << "running..." << endl;

   system("pause");
   return 0;
}
Code:
// gradebook.cpp
#include <iostream>
using namespace std;

#include "GradeBook.h"

GradeBook::GradeBook( string name, string iname )
{
   setCourseName( name );
   setInstructor( iname );
} 

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

string GradeBook::getCourseName()
{
   return courseName;
}

void GradeBook::setInstructor( string iname )
{
   instructorName = iname; 
}

string GradeBook::getInstructor()
{
   return instructorName;
}
Code:
// gradebook.h
#include <string>
using namespace std;

class GradeBook
{
public:
   GradeBook( string, string );
   void setCourseName( string );
   string getCourseName();
   void setInstructor( string );
   string getInstructor();
   void displayMessage();
private:
   string courseName; 
   string instructorName;
};
The assignment is in Deitel's C How to Program 5th Edition, Chapter 19. Review question 19.11

DevC++ is giving me "no matching function for call to `GradeBook::GradeBook()' " on line 13 on main.cpp. I'm not understanding or even seeing that error.

Thanks for any help.

**EDIT: Proof I've been starring at this too long...I was missing parenthesis, but I'll probably need help anyway. o_o **

Last edited by The.Merridian; 09-08-2008 at 03:35 PM. Reason: Self fixed...sort of
The.Merridian is offline   Reply With Quote
Old 09-08-2008, 03:49 PM   #2 (permalink)
The.Merridian
Recruit
 
Join Date: Aug 2008
Posts: 6
The.Merridian is on a distinguished road
Nope, still stuck...
The.Merridian is offline   Reply With Quote
Old 09-08-2008, 07:30 PM   #3 (permalink)
landonmkelsey
Code Monkey
 
Join Date: Aug 2008
Posts: 74
landonmkelsey is on a distinguished road
messed up your naming convention...in a rush...

Code:
//function main
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

#include "gradebook.h"

int main()
{
    gradebook myGradebook;

           cout << "running..." << endl;

              system("sleep 5 ");
                 return 0;
                 }
Code:
// gradebook.h
 #include <string>
 using namespace std;

 class gradebook
 {
 public:
    gradebook( string, string );
    gradebook(  );
       void setCourseName( string );
          string getCourseName();
             void setInstructor( string );
                string getInstructor();
                   void displayMessage();
                   private:
                      string courseName;
                         string instructorName;
                         };
Code:
//  gradebook.cpp
 #include <iostream>
 using namespace std;

 #include "gradebook.h"

gradebook::gradebook(){}
 gradebook::gradebook( string name, string iname )
 {
    setCourseName( name );
       setInstructor( iname );
 }

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

          string gradebook::getCourseName()
          {
             return courseName;
             }

             void gradebook::setInstructor( string iname )
             {
                instructorName = iname;
                }

                string gradebook::getInstructor()
                {
                   return instructorName;
                   }
landonmkelsey is offline   Reply With Quote
Old 09-09-2008, 05:37 AM   #4 (permalink)
The.Merridian
Recruit
 
Join Date: Aug 2008
Posts: 6
The.Merridian is on a distinguished road
Thank you. I got the program functioning correctly now
The.Merridian is offline   Reply With Quote
Old 09-09-2008, 06:07 AM   #5 (permalink)
landonmkelsey
Code Monkey
 
Join Date: Aug 2008
Posts: 74
landonmkelsey is on a distinguished road
lest the exercise be in vain, spend some time understanding the concepts

ask a question and get answers

C++ requires prodigious study

One may put in cout statements to trace the operation of the program

BTW C# has "properties" that get rid of the clutter of set and get methods

Last edited by landonmkelsey; 09-09-2008 at 06:08 AM. Reason: add sentence
landonmkelsey is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help me.. how to apply inheritance&polymorphsm in GUI ice Java 7 03-27-2006 01:27 PM
Is a Static Reference to an Object Garbage Collected? dancer Java 1 03-01-2005 11:50 AM


All times are GMT -8. The time now is 05:18 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting