第二章题目

第一题

#include<iostream>
using namespace std;
class Time{
public:
void set_time(void);
void show_time(void);
int hour;  int minute; int sec;
};Time t;
int main(){
 t.set_time();
 t.show_time(); 
return 0;
}
void Time:: set_time(void){
cin>>t.hour;
cin>>t.minute;
cin>>t.sec;  
}
void Time:: show_time(void){
cout<<t.hour<<":"<<minute<<":"<<sec<<endl;
}

第二题

#include<iostream>
using namespace std;
class Time{
private:
int hour;
int minute;
int sec;
public:
void set_time(){
cin>>hour>>minute>>sec;
}
void show_time(){
cout<<hour<<":"<<minute<<":"<<sec<<endl;

}
};
int main(){
Time t;
t.set_time();
t.show_time();

return 0;
} 


第三题

#include<iostream>
using namespace std;
class Time
{
private:
 int hour; 
 int minute; 
 int sec; 
public: 
 void shuru(); 
 void shuchu(); 
};
int main()
{
 Time t1;
 t1.shuru(); 
 t1.shuchu();
 return 0;
}
void Time:: shuru()
{<pre name="code" class="html">#include <iostream> 
#include"student.h"
using namespace std;
void Student::display(){
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
void Student::set_value(){
cin>>num>>name>>sex;
}

cin >> hour ; cin >> minute; cin >> sec; }void Time ::shuchu(){ cout << hour << ":" << minute << ":" << sec << endl;}

 

第四题

#include <iostream>
using namespace std;
class Student {
public:
void display();
void set_value();
private:int num;
string name;
char sex;
}; 
#include <iostream> 
#include"student.h"
using namespace std;
void Student::display(){
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
void Student::set_value(){
cin>>num>>name>>sex;
}


#include <iostream> 
#include "student.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main() {
Student stud1,stud2;
stud1.set_value();
stud1.display() ;
stud2.set_value() ;
stud2.display() ;
return 0;
}



第五题

#include<iostream>
#include"arraymax.h"
using namespace std;
int main()
{
 Array_max arrmax;
 arrmax.set_value();
 
 arrmax.max_value();
 arrmax.show_value();
 return 0;
}
(arraymax.h)
#include<iostream>
#include"arraymax.h"

using namespace std;
int main()
{
 Array_max arrmax;
 
 arrmax.set_value();
 arrmax.max_value();
 arrmax.show_value();
 return 0;
}
(arraymax.cpp)
#include<iostream>
using namespace std;

#include"arraymax.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[10];
 for(i = 1; i < 10; i++)
  if( array[i] > max) max = array[i];
}

void Array_max::show_value()
{
 cout << " max = " << max;
}

第六题

#include<iostream>    
using namespace std;
class Volume{
private:
int length;
int width;
int height;
public:
void set_volume(void){
cin>>length;
cin>>width;
cin>>height;}
    void  result_volume(void) {
cout<<length*width*height<<endl;
}



};
Volume v1,v2,v3;
int main(){

v1.set_volume();
v1.result_volume();
v2.set_volume();
v2.result_volume();
v3.set_volume();
v3.result_volume();

return 0;
} 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值