第二章

第一题
#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;
 }
using namespace std; lass Tim
 
 
第二题
#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="" />

 



 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值