구조 훈련

1. 학생 정보 tStudent {문자 이름 [100] BOOL isMale; INT 치 수학} 구조에 주어진 학생, 복수의 정보를 설명하는 학생 이름 입력, 학생 이름의 출력 언어 획득, 수학 총 점수.

#include<iostream>
#include<cstring>
using namespace std;
struct tstudent
{   char  name[100]; 
    bool isMale; 
    int chi, math, total;
}stu[10]={{"Li1", 1, 100, 100},{"Li2", 0, 100, 99},{"Hznag1", 1, 99, 90},{"zhang2", 0, 90, 100}};
int main()
{
 char  name[100]; 
 cin>>name;
 for(int i=0;i<4;i++)
 {
  if(!strcmp(name,stu[i].name))	//strcmp()将输入姓名与学生姓名作比较,若正确,结果为0,非运算后为,输出相关信息。
 {
   stu[i].total=stu[i].chi+stu[i].math;
   cout<<stu[i].name<<" "<<stu[i].chi<<" "<<stu[i].math<<" "<<stu[i].total;
  }
 }
}

2. 학생 정보 tStudent {문자 이름 [100] 부울 isMale, INT 카이, 수학} 구조와 함께, 정보를 제공 학생들의 숫자, 모든 출력 소년, 언어 점수, 수학, 점수의 이름을 설명했다.

#include<iostream>
using namespace std;
struct tstudent
{
 char  name[100]; 
 cin>>name;
 bool isMale; 
 int chi, math,total;
}stu[10]={{"a",1,100,100},{"b",0,99,98},{"c",1,98,100},{"d",0,100,99}};
int main()
{
 for(int i=0;i<4;i++)
 {
  if(stu[i].isMale==1)
  {
   stu[i].total=stu[i].chi+stu[i].math;
   cout<<stu[i].name<<" "<<stu[i].chi<<" "<<stu[i].math<<" "<<stu[i].total;
  }
 }
}
게시 된 123 개 원래 기사 · 원의 찬양 (109) · 조회수 6517

추천

출처blog.csdn.net/huangziguang/article/details/104966242