Stu.h
#include <string>
#include <iostream>
using namespace Std;
Class Stu
{
Private
String name; //Student Name
Float Chinese; //language scores
float math; //Math Score
Then write it down.
Public
void Setstudent (string, float, float);
void Show ();
void SetName (String);
String GetName ();
float average ();
};
-----------------------------------------------
Stu.cpp
#include <string>
#include "Stu.h"
void Stu::setstudent (String A, float B, float c)
{
name = A;
Chinese = b;
math = c;
}
void Stu::show ()
{
cout << "Name:" << name << Endl;
cout << "score:" << Chinese << ' \ t ' << this->math << Endl;
cout << "Average:" << (Chinese + math)/2 << ' \ t ';
cout << "Sum:" << Chinese + math << endl << Endl;
}
void Stu::setname (String a)
{
name = A;
}
String Stu::getname ()
{
return name;
}
Float Stu::average ()
{
Return ((Chinese + math)/2);
}
--------------------------------------------------
Main.cpp
#include <iostream>
#include "Stu.h"
using namespace Std;
int main ()
{
Stu S1, S2;
S1.setstudent ("Lin Daiyu", 98, 96); Object Set initial value
S2.setstudent ("Jia Baoyu", 90, 88); Object Set initial value
S1.show ();//Print information
S2.show ();//Print information
S1.setname ("Xue Baochai");//Reset the name of the P1 object
S1.show ();
cout << "S1. Name: "<< s1.getname () << endl;//Print the name of the object
cout << "s1.average:" << s1.average () << endl;//The results of the printed object
GetChar ();
return 0;
}
Third week item -4