第四章作业:4.17:建立一个对象数组,内放6个学生的数据(学号,成绩),用指针向数组首元素,输出第2,4,6个学生的数据。
2015-06-29 23:13
866 查看
#include<iostream>
#include<string>
using namespace std;
class student {
public:
void show1();
student (string a,double b)
{ score=b;
name=a;
}
private:
string name;
double score;
};
void student:: show1()
{
cout<<name<<" "<<score<<endl;
}
void show(student q)
{
q.show1();
}
int main()
{
student stu[6]={student("小明",67),student("小红",88),student("小芳",70),student("小俊",100),
student("小兰",79),student("小军",98)};
for(int i=1;i<6;i+=2)
{
show(stu[i]);
} return 0;
}
#include<iostream>
#include<string>
using namespace std;
class student {
public:
void show1();
student (string a,double b)
{ score=b;
name=a;
}
private:
string name;
double score;
};
void student:: show1()
{
cout<<name<<" "<<score<<endl;
}
void show(student q)
{
q.show1();
}
int main()
{
student stu[6]={student("小明",67),student("小红",88),student("小芳",70),student("小俊",100),
student("小兰",79),student("小军",98)};
for(int i=1;i<6;i+=2)
{
show(stu[i]);
} return 0;
}
相关文章推荐
- sprintf为什么有安全隐患
- startService与bindService的区别
- Spring中 @Autowired标签与 @Resource标签 的区别(转)
- Sublime3使用记录 (Windows)
- 【Leetcode】Isomorphic Strings
- MySQL的数据类型
- iOS protocol buffer的使用
- EF和LINQ 调用存储过程
- [PHP]流程控制的替代语法:endif/endwhile/endfor使用介绍
- Swift 归档解档
- Oracle PLSQL Demo - 31.执行动态SQL拿一个返回值
- [LintCode] 链表插入排序
- sql 面试题目
- Android一些关键函数和类的分析-startActivity
- 线程同步
- Swift中 使用位移枚举
- with 语句
- Oracle PLSQL Demo - 29.01.Function结构模板 [无入参] [有返回]
- 几种任务调度的 Java 实现方法与比较
- BZOJ2763 [JLOI2011]飞行路线(分层图最短路)