C++作业
来源:互联网 发布:for在c语言中的作用 编辑:程序博客网 时间:2024/05/01 06:15
#include <iostream>
using namespace std;
class Time
{
public:
voidset_time();
voidshow_time();
private: //成员改为公用的
int hour;
int minute;
int sec;
};
void Time::set_time() //在main函数之前定义
{
cin>>hour;
cin>>minute;
cin>>sec;
}
void Time::show_time() //在main函数之前定义
{
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
int main()
{Time t1;
t1.set_time();
t1.show_time();
return 0;
}
2、
#include <iostream>
using namespace std;
class Time
{public:
void set_time(void)
{cin>>hour;
cin>>minute;
cin>>sec;
}
void show_time(void)
{cout<<hour<<":"<<minute<<":"<<sec<<endl;}
private: int hour;
int minute;
int sec;
};
Time t;
int main()
{
t.set_time();
t.show_time();
return 0;
}
3、
#include <iostream>
using namespace std;
class Time
{public:
void set_time(void);
void show_time(void);
private:
int hour;
int minute;
int sec;
};
void Time::set_time(void)
{cin>>hour;
cin>>minute;
cin>>sec;
}
void Time::show_time(void)
{cout<<hour<<":"<<minute<<":"<<sec<<endl;}
Time t;
int main()
{ t.set_time();
t.show_time();
return 0;
}4、
#include <iostream>
using namespace std;
class Time
{
public:
void set_time(void)
{
cin>>hour>>minute>>sec;
}
void show_time(void)
{
cout<<hour<<":"<<minute<<":"<<sec;
}
private:
int hour,minute,sec;
};
Time t;
int main()
{
t.set_time();
t.show_time();
return 0;
}
6、
#include<iostream>
using namespacestd;
class Cuboid
{public:
void get_value();
void volume();
void display();
private:
float length,width,height,vol;
};
void Cuboid::get_value()
{
cin>>length>>width>>height;
};
void Cuboid::volume()
{
vol=length*width*height;
}
void Cuboid::display()
{
cout<<vol<<endl;
}
int main()
{
Cuboid c1,c2,c3;
c1.get_value();
c1.volume();
cout<<"The volume of c1 is:";
c1.display();
c2.get_value();
c2.volume();
cout<<"The volume of c2 is:";
c2.display();
c3.get_value();
c3.volume();
cout<<"The volume of c3 is:";
c3.display();
return 0;
}
- c 作业
- c作业
- C作业
- c作业
- c作业
- c作业
- c作业
- c作业
- 【C语言】【unix c】作业 前台作业和后台作业
- C语言期中作业
- C语言期末作业
- C基础作业
- C语言小作业
- c语言作业2
- C语言小作业
- 第一次C程序设计作业
- 第一次C程序设计作业
- 第一次C程序设计作业
- selenium+java+testNG+pageObject深入理解自动化测试框架
- BZOJ 3931 CQOI2015 网络吞吐量 Dijkstra+网络流
- Android WebView详解
- spring-data-jpa 学习笔记一(转)
- 第二章第二十一题
- C++作业
- 第二章第二十二题
- Gray Code
- dbca建库报错exception in thread main
- selenium+java自动化测试框架之元素管理篇(yaml)
- [leetcode]48 Binary Tree Right Side View
- Android LayoutInflater原理分析,带你一步步深入了解View(一)
- 使用FileInputStream和FileOutputStream读写sdcard卡下的文件
- 黑马程序员——面向对象-多肽