C++ Object-Oriented Example

 // Main.cpp
  #include <iostream>  //Include 'system'
  #include <cstdlib>
  
  #include "grade_book.h"
  
  using namespace std;

int main(int argc, char **argv)
{
     
	GradeBook myGradeBook;//Warning here!
        //refer to http://stackoverflow.com/questions/4846959/request-for-member-in-which-is-of-non-class-type
 
	cout<<"Welcome to GardeBook for "<<myGradeBook.getCourseName()<<endl;
	
	 system("PAUSE");
	 return 0;
}


  //GrdeBook.h
  #ifndef GRADEBOOK_H
  #define GRADEBOOK_H
  #include <string>
  using namespace std;//'string' type is reside 'std' space
  
  class GradeBook {

public:
		GradeBook();
		~GradeBook();
		void setCourseName(string name);
		string getCourseName();
private:
		string courseName;
};

#endif // GRADEBOOK_H


 //GradeBook.cpp

 #include "grade_book.h"

GradeBook::GradeBook()
{
     courseName = "Jupiter ";       
}

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

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

GradeBook::~GradeBook()
{
}



structure:
C++ Object-Oriented Example

你可能感兴趣的:(example)