您的位置:首页 > 大数据 > 人工智能

有一个结构体变量stu,内含学生学号,姓名和三门课成绩。要求在main函数中为各位成员赋值,在另一函数print中将他们输出。

2012-12-10 23:04 2879 查看
// 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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐