C++ 第二章编程题
来源:互联网 发布:双11数据作假 编辑:程序博客网 时间:2024/06/16 06:23
2.2#include<iostream>
using namespace std;
class Time
{
public:
void cin_Time()
{
cin>>hour>>minute>>sec;
}
void cout_Time()
{
cout<<hour<<":"<<minute<<":"<<sec;
}
private:
int hour;
int minute;
int sec;
};
int main()
{
Time t;
t.cin_Time();
t.cout_Time();
return 0;
//xt2-4-1.cpp(main.cpp)
#include <iostream>
using namespace std;
#include "xt2-4.h"
int main()
{Student stud;
stud.set_value();
stud.display();
return 0;
}
//xt2-4-2.cpp(即student.cpp)
#include "xt2-4.h"
#include <iostream>
using namespace std;
void Student::display( )
{ cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
void Student::set_value()
{ cin>>num;
cin>>name;
cin>>sex;
}
5:
//xt2-5-1.cpp(file1.cpp)
#include <iostream>
#include "xt2-5.h"
int main()
{Array_max arrmax;
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();
return 0;
}
//xt2-5-2.cpp(arraymax.cpp)
#include <iostream>
using namespace std;
#include "xt2-5.h"
void Array_max::set_value()
{ int i;
for (i=0;i<10;i++)
cin>>array[i];
}
void Array_max::max_value()
{int i;
max=array[0];
for (i=1;i<10;i++)
if(array[i]>max) max=array[i];
}
void Array_max::show_value()
{cout<<"max="<<max<<endl;
}
6:
#include <iostream>
using namespace std;
class Box
{public:
void get_value();
float volume();
void display();
public:
float lengh;
float width;
float height;
};
void Box::get_value()
{ cout<<"please input lengh, width,height:";
cin>>lengh;
cin>>width;
cin>>height;
}
float Box::volume()
{ return(lengh*width*height);}
void Box::display()
{ cout<<volume()<<endl;}
int main()
{Box box1,box2,box3;
box1.get_value();
cout<<"volmue of bax1 is ";
box1.display();
box2.get_value();
cout<<"volmue of bax2 is ";
box2.display();
box3.get_value();
cout<<"volmue of bax3 is ";
box3.display();
return 0;
}
using namespace std;
class Time
{
public:
void cin_Time()
{
cin>>hour>>minute>>sec;
}
void cout_Time()
{
cout<<hour<<":"<<minute<<":"<<sec;
}
private:
int hour;
int minute;
int sec;
};
int main()
{
Time t;
t.cin_Time();
t.cout_Time();
return 0;
}
2.3 include<iostream>
using namespace std;
class Time
{
public:
void cin_Time();
void cout_Time();
private:
int hour;
int minute;
int sec;
};
int main()
{
Time t;
t.cin_Time();
t.cout_Time();
return 0;
}
void Time::cin_Time()
{
cin>>hour>>minute>>sec;
}
void Time::cout_Time()
{
cout<<hour<<":"<<minute<<":"<<sec;
}
2.4
//xt2-4-1.cpp(main.cpp)
#include <iostream>
using namespace std;
#include "xt2-4.h"
int main()
{Student stud;
stud.set_value();
stud.display();
return 0;
}
//xt2-4-2.cpp(即student.cpp)
#include "xt2-4.h"
#include <iostream>
using namespace std;
void Student::display( )
{ cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
void Student::set_value()
{ cin>>num;
cin>>name;
cin>>sex;
}
5:
//xt2-5-1.cpp(file1.cpp)
#include <iostream>
#include "xt2-5.h"
int main()
{Array_max arrmax;
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();
return 0;
}
//xt2-5-2.cpp(arraymax.cpp)
#include <iostream>
using namespace std;
#include "xt2-5.h"
void Array_max::set_value()
{ int i;
for (i=0;i<10;i++)
cin>>array[i];
}
void Array_max::max_value()
{int i;
max=array[0];
for (i=1;i<10;i++)
if(array[i]>max) max=array[i];
}
void Array_max::show_value()
{cout<<"max="<<max<<endl;
}
6:
#include <iostream>
using namespace std;
class Box
{public:
void get_value();
float volume();
void display();
public:
float lengh;
float width;
float height;
};
void Box::get_value()
{ cout<<"please input lengh, width,height:";
cin>>lengh;
cin>>width;
cin>>height;
}
float Box::volume()
{ return(lengh*width*height);}
void Box::display()
{ cout<<volume()<<endl;}
int main()
{Box box1,box2,box3;
box1.get_value();
cout<<"volmue of bax1 is ";
box1.display();
box2.get_value();
cout<<"volmue of bax2 is ";
box2.display();
box3.get_value();
cout<<"volmue of bax3 is ";
box3.display();
return 0;
}
0 0
- C专家编程第二章
- C语言程序设计(第二版)第3章编程题
- C语言程序设计(第二版)第6章编程题
- C Primer Plus 第二章 编程练习 1-7题
- C语言程序设计现代方法(第二版)_______第二、三、四章编程题部分
- C专家编程第二章学习笔记
- C专家编程学习之第二章
- [C++]第二章:基本编程语句
- Linux C编程一站式学习第二章
- C和指针第二章编程练习
- C Primer Plus第二章编程练习
- C++ 第二章编程题
- C专家编程第二天
- Pointer On C-第二章编程练习第一题函数调用
- 记录——《C Primer Plus (第五版)》第八章编程练习第二题
- 记录——《C Primer Plus (第五版)》第九章编程练习第二题
- 记录——《C Primer Plus (第五版)》第十章编程练习第二题
- 记录——《C Primer Plus (第五版)》第十一章编程练习第二题
- 最小二乘法实现数据拟合
- L2---net_device---lwevent
- 【算法之链表(三)】单链表中,在仅允许使用一个指针的情况下,在指定的节点前面插入以及删除一个节点
- netfilter---(nf_hooks[][]).jpg
- GemU安装日志
- C++ 第二章编程题
- 【VC++】踏入VC++--windows API 窗口的创建,总结
- iOS总结
- netfilter---conntrack---nf_ct_ext
- javase_io_基础总结
- String系列简介
- 博客开通
- 链表学习笔记 --- 循环链表
- Google Code Jam 2015资格赛