El editor de diagramas UML
se muestra a continuación
La determinación de clase UML
#ifndef MYFUNCTION_H_INCLUDED
#define MYFUNCTION_H_INCLUDED
#include <string>
using namespace std;
class GradeBook
{
public://access specifier公共使用
GradeBook();//constructor 构造涵式(特点:它的名字是和类的名字(class GradeBook)是一样的; 前面没有声明
GradeBook(string);
void setCourseName(string);
string getCourseName();
void dispiay();
private://私有的
string courseName;
};
#endif // MYFUNCTION_H_INCLUDED
La finalización de la clase funcional de preparación
#include <iostream>
#include <string>
#include "myFunction.h"
using namespace std;
GradeBook::GradeBook(string name)
{
courseName = name ;
}
GradeBook::GradeBook()
{
courseName = "New Course";
}
void GradeBook::setCourseName(string name)//::(作用域分辨运算符)scope resolution operator
{
courseName = name;
}
string GradeBook::getCourseName()
{
return courseName;
}
void GradeBook::dispiay()
{
cout << "Welcome to the grade book of " << courseName << endl;
}
Los principales contenidos
#include <iostream>
#include <string>
#include "myFunction.h"
using namespace std;
int main()
{
int a;
string nameOfCourse;
GradeBook myGradeBook;//create an object, myGradeBook
GradeBook secondGradeBook;
GradeBook thirdGradeBook("Programing Language");
myGradeBook.dispiay();
secondGradeBook.dispiay();
thirdGradeBook.dispiay();
cout << "Please enter the name of this grade book ";
getline(cin, nameOfCourse);// >> nameOfCourse;
myGradeBook.setCourseName(nameOfCourse);
myGradeBook.dispiay();
cout << "Using getCourseName:" << myGradeBook.getCourseName() << endl;
return 0;
}