// 121209 第七章例7.5.cpp : 定义控制台应用程序的入口点。
//
/*
* Copyright (c) 2012, 烟台大学计算机学院
* All rights reserved.
* 作 者: 刘同宾
* 完成日期:2012 年 12 月 09 日
* 版 本 号:v1.0
*
* 输入描述: 有一个结构体变量stu,内含学生学号,姓名和三门课成绩。
* 要求在main函数中为各位成员赋值,在另一函数print中将他们输出。
* 问题描述:
* 程序输出:
* 问题分析:略
* 算法设计:略
*/
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
struct student //声明结构体类型student
{
int num;
string name;
float score[3];
};
int main()
{
void print(student); //函数声明,形参类型为结构体student
student stu; //定义结构体变量
stu.num=12345; //以下五行对结构体变量各成员赋值
stu.name="liu tong bin";
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.5;
print(stu); //调用print函数,输出stu各成员的值
return 0;
}
void print(student stu)
{
cout<<stu.num<<" "<<stu.name<<" "<<stu.score[0]
<<" "<<stu.score[1]<<" "<<stu.score[2]<<" "<<endl;
}
有一个结构体变量stu,内含学生学号,姓名和三门课成绩。要求在main函数中为各位成员赋值,在另一函数print中将他们输出。
最新推荐文章于 2022-08-31 15:01:40 发布