Third week item-4

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.