The concepts of entity, object, and class

  • Entity: Things that exist objectively, such as a person, a school, a class, a bank, etc.
  • Attributes: The features and functions of entities are collectively referred to as attributes.
  • Object = feature + function ( object = data + function )
  • Class: A collection of objects with the same characteristics and functions

Target students

  • Student characteristics: class student number name gender
  • Student's function: learn to eat exercise

Target is TV

  • Features of TV sets: model, price, size
  • TV functions: adjust the volume, adjust the channel, set the picture quality
#include <iostream>
#include <cmath>
#include <windows.h>
using namespace std;
class Clock
{
    
     //钟表类 数据(小时 分钟 秒 价格) 功能(设置时间 运转 报时响铃 显示时间)
private:
	int Hour;//小时
    int Minute;//分
	int Second;//秒
	double Price;// 价格
public:
	void Set(int H,int M,int S,double P);//设置
	void Run();//运转十秒
	void Report();//报时响铃
	void Display(){
    
    cout<<Hour<<":"<<Minute<<":"<<Second;}//显示时间
};
void Clock::Set(int H,int M,int S,double P)
{
    
    
	Hour=H;
    Minute=M;
	Second=S;
    Price=P;
}
void Clock::Run()
{
    
    
	for(int i=1;i<11;i++)
	{
    
    
		Second++;
		if(Second==60)
		{
    
    
		   Second=0;
		   Minute++;
		   if(Minute==60)
		   {
    
    
			   Minute=0;
			   Hour++;
			   if(Hour==24)
			   {
    
    
				   Hour=0;
			   }
		   }
		}
	cout<<"\r                    \r";//不换行 光标返回当前首位
	Display();
	Sleep(1000);
	}
}
void Clock::Report()
{
    
    
	Display();
	if(Minute==0&&Second==0)
	{
    
    
		for(int j=0;j<Hour;j++)
		{
    
    
			cout<<"\007";
			Sleep(1000);
		}
	}
}
int main()
{
    
    
Clock Switzerland;
Switzerland.Set(0,0,0,2000.0);
cout<<"钟表设置的时间 \n";
Switzerland.Display();
Switzerland.Run();
system("pause");//暂停
Switzerland.Set(5,59,50,3000.0);
cout<<"\n钟表设置的时间 \n";
Switzerland.Display();
Switzerland.Run();
cout<<endl;
Switzerland.Report();
return 0;
}

Guess you like

Origin blog.csdn.net/qq_38208612/article/details/106157593