第一题
#include<iostream>
using namespace std;
class Time{
<span style="white-space: pre;"></span>public:
<span style="white-space: pre;"></span>void set_time(void);
<span style="white-space: pre;"></span>void show_time(void);
<span style="white-space: pre;"></span>int hour;<span style="white-space: pre;"> </span> int minute;<span style="white-space: pre;"> </span>int sec;<span style="white-space: pre;"></span>
};Time t;
int main(){
t.set_time();
t.show_time();
<span style="white-space: pre;"></span>return 0;
}
void Time:: set_time(void){
<span style="white-space: pre;"></span>cin>>t.hour;
<span style="white-space: pre;"></span>cin>>t.minute;
<span style="white-space: pre;"></span>cin>>t.sec;<span style="white-space: pre;"> </span>
}
void Time:: show_time(void){
<span style="white-space: pre;"></span>cout<<t.hour<<":"<<minute<<":"<<sec<<endl;
}
第二题
#include<iostream>
using namespace std;
class Time
{
private:
int hour;
int minute;
int sec;
public:
void shuru()
{
cin >> hour ;
cin >> minute;
cin >> sec;
}
void shuchu()
{
cout << hour << ":" << minute << ":" << sec << endl;
}
};
int main()
{
Time t1;
t1.shuru();
t1.shuchu();
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()
{
cin >> hour ;
cin >> minute;
cin >> sec;
}
void Time ::shuchu()
{
cout << hour << ":" << minute << ":" << sec << endl;
}
第四题
(main.cpp)
#include<iostream>
#include"student.h"
using namespace std;
int main()
{
Student t;
t.set_value();
t.display();
return 0 ;
}
(student.cpp)
#include<iostream>
#include<string>
#include"student.h"
using namespace std;
void Student::set_value()
{
cin >> num;
cin >> name;
cin >> sex;
}
void Student::display()
{
cout << "num:" << num << endl;
cout << "name:" << name << endl;
cout << "sex:" << sex << endl;
}
(stdudent.h)
#include<iostream>
using namespace std;
class Student
{
public:
void display();
void set_value();
private:
int num;
string name;
char sex;
};
第五题
(file.cpp)
#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 tiji
{
private:
int length;
int width;
int height;
public:
void shuru();
void shuchu();
};
void tiji::shuru()
{
cout << "请输入此长方柱的长:";
cin>> length;
cout << "请输入此长方柱的宽:";
cin >> width;
cout<< "请输入此长方柱的高:" ;
cin>> height;
}
void tiji::shuchu()
{
int a;
a = length * width * height;
cout << "该长方柱的体积为:" << a << endl <<endl;
}
int main()
{
tiji t;
int i;
for(i = 0; i < 3; i++)
{
t.shuru();
t.shuchu();
}
return 0;
}
<img src="https://img-blog.csdn.net/20150420212157465?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbG9uZ3hpdWh1YQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />