C # -- week 4 lab -- Task 1 -- Define the student class and calculate the total score and average score. (Console application)

Source: Internet
Author: User

[Csharp]
/* (Start of program header annotation)
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: defines the class that describes the basic information of the student, sets the name, sets the score for the three courses, and calculates the total score and average score.
* Author: Lei hengxin
* Completion date: January 1, September 22, 2012
* Version No.: V1.0
* Description of tasks and Solutions
* Input description:
* Problem description:
* Program output:
* End the comment in the program Header
*/
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
 
Namespace Four _ week
{
Class Program
{
Static void Main (string [] args)
{
Student stu = new Student ();
Console. Write ("Enter the student's name :");
String name = Console. ReadLine ();
Console. Write ("Enter the student's Chinese score :");
Double Chinese = double. Parse (Console. ReadLine ());
Console. Write ("Enter your student's score :");
Double Math = double. Parse (Console. ReadLine ());
Console. Write ("Enter your English score :");
Double English = double. Parse (Console. ReadLine ());
 
Stu. set_name (name );
Stu. set_Math (Math );
Stu. set_English (English );
Stu. set_Chinese (Chinese );

Double sun = stu. sum_score ();
Double average = stu. average_score ();
 
Console. WriteLine ("total score of this student: {0}", sun );
Console. WriteLine ("the average score of this student is {0}", average );
Console. ReadKey (true );
}
}
 
Class Student
{
Public string name;
 
Public double Chinese;
Public double Math;
Public double English;
 
Public Student (string name, double Chinese, double Math, double English)
{
Name = "";
Chinese = 0;
Math = 0;
English = 0;
 
}
 
Public Student ()
{
Name = "";
Chinese = 0;
Math = 0;
English = 0;
 
}
 
Public void input_data ()
{
Console. WriteLine ("Name: Chinese, mathematics, and English ");
Console. WriteLine ("{0} {1} {2} {3}", name, Chinese, Math, English );
}
 
Public void set_name (string name1)
{
Name = name1;
}
Public void set_Chinese (double Chinese1)
{
Chinese = Chinese1;
}
Public void set_Math (double Math1)
{
Math = Math1;
}
Public void set_English (double English1)
{
English = English1;
}
 
Public double sum_score ()
{
Double sum = Chinese + Math + English;
Return sum;
}
Public double average_score ()
{
Double average = sum_score ()/3;
Return average;
}
}
}

 
Running result:

Related Article

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.