當前位置:編程學習大全網 - 編程語言 - C++程序設計 學生身高調查

C++程序設計 學生身高調查

根據您提供的信息,大致有人名、編號、身高。

程序如下:

#include<iostream>

#include<stdlib.h>

#include<iomanip>

struct?student

{

char?name[20];

int?number;

double?height;

}a[100];

using?namespace?std;

int?main()

{

int?i=0,n,choice,j,num;

char?name[20];

cout<<"身高調查"<<endl;

loop:?cout<<"1?記錄信息."<<endl

<<"2?瀏覽信息."<<endl

<<"3?查詢信息."<<endl

<<"4?退出."<<endl

<<"請輸入序號,按回車確定"<<endl;

cin>>choice;

if(choice==1)

{

cout<<"請輸入調查總人數:?";

cin>>n;

while(n--)

{

cout<<"姓名:?";

cin>>a[i].name;

cout<<"編號:?";

cin>>a[i].number;

cout<<"身高(cm):?";

cin>>a[i].height;

i++;

cout<<"記錄成功"<<endl;

}

system("pause");

system("cls");

goto?loop;

}

if(choice==2)

{

cout<<"姓名"<<setw(18)<<"編號"<<setw(20)<<"身高"<<endl;

for(j=0;j<i;j++)

cout<<a[j].name<<setw(20-strlen(a[j].name))<<a[j].number<<setw(20)<<a[j].height<<endl;

system("pause");

system("cls");

goto?loop;

}

if(choice==3)

{

cout<<"1?按編號查詢"<<endl

<<"2?按姓名查詢"<<endl;

cin>>choice;

if(choice==1)

{

cout<<"輸入編號:?";

cin>>num;

for(j=0;j<i;j++)

if(a[j].number==num)

{

cout<<"姓名"<<setw(18)<<"編號"<<setw(20)<<"身高"<<endl;

cout<<a[j].name<<setw(20-strlen(a[j].name))<<a[j].number<<setw(20)<<a[j].height<<endl;

system("pause");

system("cls");

goto?loop;

}

}

if(choice==2)

{

cout<<"輸入姓名:?";

cin>>name;

for(j=0;j<i;j++)

if(strcmp(a[j].name,name)==0)

{

cout<<"姓名"<<setw(18)<<"編號"<<setw(20)<<"身高"<<endl;

cout<<a[j].name<<setw(20-strlen(a[j].name))<<a[j].number<<setw(20)<<a[j].height<<endl;

system("pause");

system("cls");

goto?loop;

}

}

}

if(choice==4)

cout<<"感謝使用"<<endl;

return?0;

}

  • 上一篇:有哪些可以用手機賺錢的APP?求告知
  • 下一篇:如何搭建壹個Ghost平臺的博客
  • copyright 2024編程學習大全網