第一题
#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;
}