C++语言基础 例程 类的成员函数

简介: 贺老师的教学链接  本课讲解分清“你我”#include <iostream>using namespace std;class Time{public: void set_time(int,int,int); void show_time();private: int hour; int minute; int sec;}

贺老师的教学链接  本课讲解



分清“你我”

#include <iostream>
using namespace std;
class Time
{
public:
    void set_time(int,int,int);
    void show_time();
private:
    int hour;
    int minute;
    int sec;
};
int main( )
{
    Time t1,t2;
    t1.set_time(12,45,32);
    t2.set_time(21,32,15);
    t1.show_time();
    t2.show_time( );
    return 0;
}


void Time::set_time(int h,int m,int s)
{
    hour=h;
    minute=m;
    sec=s;
}
void Time::show_time()
{
    cout<<hour<<":";
    cout<<minute<<":";
    cout<<sec<<endl;
}


目录
相关文章
|
3天前
|
存储 编译器 C语言
c++的学习之路:5、类和对象(1)
c++的学习之路:5、类和对象(1)
19 0
|
3天前
|
C++
c++的学习之路:7、类和对象(3)
c++的学习之路:7、类和对象(3)
19 0
|
2天前
|
设计模式 Java C++
【C++高阶(八)】单例模式&特殊类的设计
【C++高阶(八)】单例模式&特殊类的设计
|
2天前
|
编译器 C++
【C++基础(八)】类和对象(下)--初始化列表,友元,匿名对象
【C++基础(八)】类和对象(下)--初始化列表,友元,匿名对象
|
6天前
|
存储 安全 C语言
【C++】string类
【C++】string类
|
28天前
|
存储 C++ 容器
C++入门指南:string类文档详细解析(非常经典,建议收藏)
C++入门指南:string类文档详细解析(非常经典,建议收藏)
37 0
|
28天前
|
存储 编译器 C语言
C++入门: 类和对象笔记总结(上)
C++入门: 类和对象笔记总结(上)
33 0
|
存储 编译器 Linux
标准库中的string类(中)+仅仅反转字母+字符串中的第一个唯一字符+字符串相加——“C++”“Leetcode每日一题”
标准库中的string类(中)+仅仅反转字母+字符串中的第一个唯一字符+字符串相加——“C++”“Leetcode每日一题”
|
8天前
|
编译器 C++
标准库中的string类(上)——“C++”
标准库中的string类(上)——“C++”
|
8天前
|
编译器 C++
自从学了C++之后,小雅兰就有对象了!!!(类与对象)(中)——“C++”
自从学了C++之后,小雅兰就有对象了!!!(类与对象)(中)——“C++”

热门文章

最新文章