C++ 第二章编程题
2015-04-14 12:10
197 查看
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;
}
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;
}
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;
}
相关文章推荐
- C++ Primer Plus 第六版 第二章编程题解题writeup
- 数据结构与算法分析C++表述第二章编程题
- C++对象模型 第二章 构造函数语意学
- 2017京东春招C/C++编程题(1)——站队
- 多态与虚函数编程题 #3(C++程序设计第6周)
- 腾讯笔试编程题:算法基础-字符移位(C++)
- 采购单-京东2017在线笔试编程题C++
- C++primer plus第六版课后编程题答案 6.3
- C++ Primer Plus 第六版(中文版)课后编程题----第五章
- c/c++编程题 之 字符串分解
- C++primer plus第六版课后编程题答案7.1
- 《C++ concurrency in action》第二章解析
- 百度笔试编程题:爬行的蚂蚁(c++)
- POJ C++程序设计 编程题#2 输出指定结果一
- 爱奇艺2018秋季校招C++工程师(第三场)编程题 - 题解
- C++primer plus第六版课后编程题答案7.5
- 《C++ Primer Plus(第六版)》(21)(第十一章 使用类 编程题答案2)
- C++ Primer Plus 第六版 第三章编程题解题writeup
- C++primer plus第六版课后编程题答案 7.7
- C++primer plus第六版课后编程题答案7.10