- #include <iostream>
- using namespace std;
- class Time
- {
- private:
- int hour;
- int minute;
- int sec;
- public:
- void set_time()
- {
- cin>>hour;
- cin>>minute;
- cin>>sec;
- }
- void show_time()
- {
- cout<<hour<<minute<<sec;
- }
- };
- int main()
- {
- Time t1;
- t1. set_time();
- t1. show_time();
- return 0;
- }
3.
- #include <iostream>
- 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;
- cin>>minute;
- cin>>sec;
- }
- void Time::show_time()
- {
- cout<<hour<<" "<<minute<<" "<<sec;
- }
- int main()
- {
- Time t1;
- t1. set_time();
- t1. show_time();
- return 0;
- }
4.
#include<iostream>
#include<string>
using namespace std;
class student
{
private:
int num;
string name;
char sex;
public:
void set_value();
void disaplay();
};
void student::set_value()
{
cin>>num;
cin>>name;
cin>>sex;
}
void student::disaplay()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
int main()
{
student stud;
stud.set_value();
stud.disaplay();
return 0;
}
5.
- filel.cpp:
- #include <iostream>
- #include "arraymax.h"
- int main()
- {
- Array_max arrmax;
- arrmax.set_vaule();
- arrmax.max_vaule();
- arrmax.show_vaule();
- return 0;
- }
- arrymax.h:
- using namespace std;
- class Array_max
- {
- public:
- void set_vaule();
- void max_vaule();
- void show_vaule();
- private:
- int array[10];
- int max;
- };
- arraymax.cpp:
- #include<iostream>
- #include"arraymax.h"
- void Array_max::set_vaule()
- {
- int i;
- for(i=0;i<10;i++)
- cin>>array[i];
- }
- void Array_max::max_vaule()
- {
- int i;
- max=array[0];
- for(i=0;i<10;i++)
- if(array[i]>max) max=array[i];
- }
- void Array_max::show_vaule()
- {
- cout<<"max="<<max;
- }
6.
- #include <iostream>
- using namespace std;
- class tiji
- {
- private:
- float length,width,height;
- public:
- void set();
- void disaplay();
- };
- void tiji::set()
- {
- cin>>length;
- cin>>width;
- cin>>height;
- }
- void tiji::disaplay()
- {
- float v;
- v=length*width*height;
- cout<<v<<endl;
- }
- int main()
- {
- tiji stu;
- stu.set();
- stu.disaplay();
- return 0;
- }