View Single Post
  #1 (permalink)  
Old 07-22-2007, 04:54 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
PT Admin
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,119
iTrader: (0)
HelloWorld is a jewel in the roughHelloWorld is a jewel in the roughHelloWorld is a jewel in the rough
Icon13 Help! What's wrong with my code?

Here's the code:

GradeBook.h

PHP Code:
#include <iostream>;

#include <string>;

class GradeBook {
public:
    
GradeBook(string); // constructor
    
void setCourseName(string);
    
string getCourseName();
    
void displayMessage();
    
void inputGrades();
    
void displayGradeReport();
    
int maximum(intintint);
private:
    
string courseName;
    
int maximumGrade;

Recursion.cpp (don't worry about the title, no connection with recursion)
PHP Code:
#include "stdafx.h"

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

#include <string>;
using std::string;
using std::getline;

#include "GradeBook.h";

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

void GradeBook::setCourseName(string name) {
    if (
name.length() <= 25) {
        
courseName name;
    } else {
        
courseName name.substr(025);
        
cout << "Name \"" << name << "\" exceed maximum length of 25.\n"
            
<< "Only gets the first 25 characters";
    }
}

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

void GradeBook::displayMessage() {
    
cout << "Welcome to " << getCourseName() << "!\n" << endl;
}

void GradeBook::inputGrades() {
    
int grade1grade2grade3;
    
cout << "Grade 1: ";
    
cin >> grade1;
    
cout << "Grade 2: ";
    
cin >> grade2;
    
cout << "Grade 3: ";
    
cin >> grade3;

    
maximumGrade maximum(grade1grade2grade3);
}

int GradeBook::maximum(int xint yint z) {
    
int max x;
    if (
max) {
        
max y;
    }
    if (
max) {
        
max z;
    }

    return 
max;
}

void GradeBook::displayGradeReport() {
    
cout << "Max grade: " << maximumGrade << endl;
}

int main() {
    
GradeBook myGradeBook("C++ PROGRAMMING");
    
myGradeBook.displayMessage();
    
myGradeBook.inputGrades();
    
myGradeBook.displayGradeReport();
    return 
0;

They said that there's something wrong with the constructor, I have no clue why...

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by HelloWorld : 07-22-2007 at 04:57 PM.
Reply With Quote