C++66页作业

本文详细介绍了C++编程的基础知识,通过66页的习题,包括时间类的定义与使用、对象属性的设置与显示、数组最大值的查找、体积计算等基本操作,帮助读者掌握C++的基本语法和编程技巧。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C++66页作业

第1——第6题

#include<iostream>//66页1题 
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>//66页2题 
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>//66页3题 
using namespace std;
class Time{
private:
int hour;
int minute;
int sec;
public:
void set_time();
void show_time();
};
void Time::set_time(){
cin>>hour>>minute>>sec;
}
void Time::show_time(){
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
int main(){
Time t;
t.set_time();
t.show_time();

return 0;



#include <iostream>//头文件67页4题 
using namespace std;
class Student {
public:
void display();
void set_value();
private:int num;
string name;
char sex;


}; 


#include <iostream>//主函数,67页4题 
#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>//主函数,67页4题 
#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>//头文件,67页第5题 
using namespace std;
class Array_max{
public:
void set_value();
void max_value();
void show_value();
private:
int array[10];
int max;
};


#include<iostream>    //成员函数定义, 67页第5题 
#include"arraymax.h"
using namespace std;
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; 

}








#include <iostream>//主函数,67页第5题 
#include"arraymax.h"
using namespace std;
 


/* run this program using the console pauser or add your own getch, system("pause") or input loop */


int main() {

Array_max arrmax;   //定义对象arrmax 
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();


return 0;
}


#include<iostream>    //67页第6题 
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、付费专栏及课程。

余额充值