C++入门实例
来源:互联网 发布:c语言null包含头文件 编辑:程序博客网 时间:2024/05/29 09:00
//C++定义类实例
#include <iostream.h>
class time
{
private:
int hours,minutes,seconds;
public:
void getinfo()
{
cin >> hours >> minutes >> seconds;
}
void display()
{
cout << hours << ':' << minutes << ':' << seconds << endl;
}
void addit(const time& aa, const time& bb)
{
hours=aa.hours+bb.hours;
minutes=aa.minutes+bb.minutes;
seconds=aa.seconds+bb.seconds;
if(seconds>=60)
{
seconds-=60;
minutes++;
}
if(minutes>=60)
{
minutes-=60;
hours++;
}
}
};
void main()
{
time one,two,three;
cout << "/n请输入第一个时间(小时 分钟 秒):" ;
one.getinfo();
cout << "/n请输入第二个时间(小时 分钟 秒):" ;
two.getinfo();
three.addit(one,two);
cout << "/n结果是:";
three.display();
}
//默认参数函数实例
#include
void repchar(char='*',int=45);
//给该函数设默认值
void main()
{
repchar();
repchar('=');
repchar('*',30);
}
void repchar(char ch,int n)
{
for(int j=0;j cout< cout< }
#include <iostream.h>
class time
{
private:
int hours,minutes,seconds;
public:
void getinfo()
{
cin >> hours >> minutes >> seconds;
}
void display()
{
cout << hours << ':' << minutes << ':' << seconds << endl;
}
void addit(const time& aa, const time& bb)
{
hours=aa.hours+bb.hours;
minutes=aa.minutes+bb.minutes;
seconds=aa.seconds+bb.seconds;
if(seconds>=60)
{
seconds-=60;
minutes++;
}
if(minutes>=60)
{
minutes-=60;
hours++;
}
}
};
void main()
{
time one,two,three;
cout << "/n请输入第一个时间(小时 分钟 秒):" ;
one.getinfo();
cout << "/n请输入第二个时间(小时 分钟 秒):" ;
two.getinfo();
three.addit(one,two);
cout << "/n结果是:";
three.display();
}
//默认参数函数实例
#include
void repchar(char='*',int=45);
//给该函数设默认值
void main()
{
repchar();
repchar('=');
repchar('*',30);
}
void repchar(char ch,int n)
{
for(int j=0;j cout< cout< }
- c#Socket通信入门实例
- C语言反汇编入门实例
- C语言反汇编入门实例
- C语言反汇编入门实例
- 嵌入式CGI入门实例(C语言版)
- C#[编程实例]-编程入门试题
- C语言反汇编入门实例
- [C#]程序设计入门与实例视频教程24:委托
- 17.C#:Entity Framework快速入门--实例篇
- Mybatis连接MySQL或者ORALE 12C 入门实例。
- C语言入门(17)——C语言数组应用的一个实例
- C实例
- c实例
- Spring-MVC入门:入门实例
- 入门C
- c 入门
- C入门
- 挑战30天C++入门极限-C/C++中利用数组名/指针进行排序实例
- 讲解有关"SELECT FOR UPDATE"的一些概念
- C++和C#的语法和功能区别
- 谁说VC效率最高?
- 数据广播方案的优化
- JAVA上传文件
- C++入门实例
- C++之重载函数
- C++之作用域的效果事例
- C++之对象操作事例
- NET中Cookie编程基础
- C++之复制构造函数
- C++之赋值操作符
- C++之类型转换构造函数
- linq 基本操作(删除、更新、插入)