首页 > 编程语言 >2023.5.10编程一小时打卡

2023.5.10编程一小时打卡

时间:2023-05-10 22:14:23浏览次数:44  
标签:10 name 输出 student age Person 2023.5 cpp 打卡

一、问题描述:

给出下面的人员基类框架:

class Person
{

protected:

     string name;
     int age;

public:

     Person();      
     Person (string p_name, int p_age);
     void display () {cout<<name<<“:”<<age<<endl;}

};

建立一个派生类student,增加以下成员数据:

int ID;//学号
float cpp_score;//cpp上机成绩
float cpp_count;//cpp上机考勤
float cpp_grade;//cpp总评成绩
     //总评成绩计算规则:cpp_grade = cpp_score * 0.9 + cpp_count * 2;

增加以下成员函数:

student类的无参构造函数

student类的参数化构造函数//注意cpp_grade为上机成绩和考勤的计算结果

void print()//输出当前student的信息

                 //其中cpp_grade输出保留一位小数
                //输出格式为ID name cpp_grade

生成上述类并编写主函数,根据输入的学生基本信息,建立一个学生对象,计算其cpp总评成绩,并输出其学号、姓名、总评成绩。

输入格式: 测试输入包含若干测试用例,每个测试用例占一行(学生姓名 学号 年龄 cpp成绩 cpp考勤)。当读入0时输入结束,相应的结果不要输出。

二、解题思路:

首先,定义一个Person类并对其进行定义数据成员name,age,然后定义构造函数对其数据进行初始化,再定义一个成员函数对其数据进行输出。然后定义一个继承类student类,先对其进行定义成员数据ID,成绩等,然后进行定义一个输出其成员数据的成员函数。在主函数中,首先定义所需数据的变量,利用输入数据的特点用while进行循环输入name时是否为零,若为零,则结束程序,若不为零,继续输出学生信息,知道输出为零为止。

三、代码实现:

 1 #include <iostream>
 2 #include<string>
 3 #include<iomanip>
 4 using namespace std;
 5 class Person
 6 {
 7 protected:
 8     string name;
 9     int age;
10 public:
11     Person();      
12     Person (string p_name, int p_age);
13     void display()
14     {
15         cout<<name<<":"<<age<<endl;
16     }
17 };
18 Person::Person (string p_name, int p_age)
19 {
20     name=p_name;
21     age=p_age;
22 }
23 class student:public Person
24 {
25 private:
26     int ID;
27     float cpp_score;
28     float cpp_count;
29     float cpp_grade;
30 public:
31     student(){}
32     student(string p_name, int p_age,int i,float s,float c):Person (p_name,p_age)
33     {
34         ID=i;
35         cpp_score=s;
36         cpp_count=c;
37         cpp_grade=s*0.9+c*2;
38     }
39     void print();
40 };
41 void student::print()
42 {
43     cout<<ID<<" "<<name<<" ";
44     cout<<fixed<<setprecision(1)<<cpp_grade<<endl;
45 }
46 int main()
47 {
48     int ID;
49     string name;int age;
50     float cpp_score;
51     float cpp_count;
52     cin >> name ;
53     while(name!="0"){
54     cin  >> ID >>age>> cpp_score >>cpp_count;
55     student a(name,age,ID,cpp_score,cpp_count);
56     a.print();
57     cin >> name ;
58     }
59     return 0;
60 }

 

标签:10,name,输出,student,age,Person,2023.5,cpp,打卡
From: https://www.cnblogs.com/lixinyao20223933/p/17384430.html

相关文章

  • 每日总结2023-05-10
    今天完成了对于Android中Fragment的了解:Fragment有自己的生命周期Fragment依赖于ActivityFragment通过getActivity()可以获取所在的Activity;Activity通过FragmentManager的findFragmentById()或findFragmentByTag()获取FragmentFragment和Activity是多对多......
  • 5.10打卡
      三、程序流程图 四、代码实现#include<bits/stdc++.h>#defineN10usingnamespacestd;main(){inti,a[N]={-3,4,7,9,13,45,67,89,100,180},low=0,high=N-1,mid,k=-1,m;printf("aÊý×éÖеÄÊý¾ÝÈçÏÂ:\n");for(i=0;i<N;i++)p......
  • 20230510
    今天学习ajax相关知识,明天准备复习连接池以及DButils。<%--CreatedbyIntelliJIDEA.User:双休日Date:2023/5/9Time:19:58TochangethistemplateuseFile|Settings|FileTemplates.--%><%@pagecontentType="text/html;charset=UTF-8"language="java&q......
  • c++打卡训练
    自守数(半成品,指没写出来,双倍给明天)流程图:伪代码:源代码:#include<iostream>usingnamespacestd;intmain(){ longinti,m; intj,n,k,a=1; for(i=0;i<=100000;i++){ n=i; m=i*i; for(j=0;n=0;j++){ n/=10; for(k=j;k>=0;k--){ a=a+a*10; if(m%a==i){ printf......
  • 2.10马克思手稿中的纯数学题
    1.问题描述马克思手稿中有一道趣味数学问题:有30个人,其中有男人、女人和小孩,他们在同一家饭馆吃饭,总共花了50先令。已知每个男人吃饭需要花3先令,每个女人吃饭需要花2先令,每个小孩吃饭需要花1先令,请编程求出男人、女人和小孩各有几人。2.#include<stdio.h>intmain(){ intx,y,z; ......
  • 5.10每日总结
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd&qu......
  • 5.10每日总结
    今天思考了接下来的团队项目要完成的任务简单的了解和学习了一些关于文本数据处理的技术知识,对未来的项目改进思考了一些基本的框架,未来还将和团队成员对项目的成品和任务进行讨论和分工。......
  • PAT Advanced 1009. Product of Polynomials
    PATAdvanced1009.ProductofPolynomials1.ProblemDescription:Thistime,youaresupposedtofind \(A×B\) where \(A\) and \(B\) aretwopolynomials.2.InputSpecification:Eachinputfilecontainsonetestcase.Eachcaseoccupies2lines,and......
  • 每日打卡-20.1
    一.问题描述编写程序提示用户输入一个班级中的学生人数n,再依次提示用户输入n个人在课程A中的考试成绩,然后计算出平均成绩,显示出来。请使用本书第9章中的数组类模板Array定义浮点型数组存储考试成绩。二.设计思路按照题目要求编写代码三.流程图四.伪代码 1五.代码......
  • 每日打卡-20.2
    一.问题描述初始化int类型数组datal[]={1,3,5,7,9,11,13,15,17,19,2,4,6,8,10,12,14,16,18,20},应用本章的直接插入排序函数模板进行排序。对此函数模板稍做修改,加入输出语句,在每插入一个待排序元素后显示整个数组,观察排序过程中数据的变化,加深对插入排序算法的理解。二.设计思路三.流程图四.......