Questions After youyuan class

Source: Internet
Author: User

 

 

 
# Include <iostream. h>
# Include "string. H"
Class score
{
PRIVATE:
Char name [8], XH [7];
Double Sx, YW, YY;

Public:
Score (char N [8], char Z [7], double A, double B, double C)
{
Strcpy (name, N );
Strcpy (XH, Z );
SX =;
YW = B;
YY = C;
 
}
Score ()
{
Cout <"Enter name :";
Cin> name;
Cout <"Enter the student ID :";
Cin> XH;
Cout <"Enter the math score :";
Cin> SX;
Cout <"enter Chinese score :";
Cin> YW;
Cout <"Enter the English score :";
Cin> YY;
}
Void display ()
{

Cout <"output name :";
Cout <name <Endl;
Cout <"output student ID :";
Cout <XH <Endl;
Cout <"total score of three subjects :";
Cout <SX + YW + YY <Endl;
Cout <"average output score :";
}

Friend double average (score );
};
Double average (score X)
{
Double PJ;
PJ = (X. SX + X. YW + X. yy)/3;
Return PJ;
}

Void main ()
{
Score S;
S. Display ();
Cout <average (s) <Endl;

}

 

Question requirements: design a score for a student, which includes a student ID, name, mathematics, Chinese, English, and average score. Then define a general function average () for calculating the average score of a student (), this function is also defined as a friend function of the score class. In the main letter, it defines the Student Score object, assigns values to members other than the initial average score through the constructor, and then calls average (), calculate the average score and assign values to all the student scores!

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.