C 언어 클래스 계승 작은 문제

3781 단어 c
#include<iostream> 
using namespace std;
class Student{
public:
	int num; 
	char* name; 
	float score; 
	Student(int num,char* name,float score):num(num),name(name),score(score){}
	void display()
	{
		cout<<"num:"<<num<<"name:"<<name<<"score:"<<score<<endl; //private:
	}
	
}; 

class Graduate:public Student{ 
public: 
	Graduate(int num,char* name,float score,float pay):Student(num, name, score), pay(pay){} //    
	void display()
	{
		cout<<"num:"<<num<<"name:"<<name<<"score:"<<score<<"score:"<<score<<endl;
	}
private: 
	float pay; 
}; 

int main() 
{
	Student stud1(1001,"Li",87.5); 
	Graduate grad1(2001,"Wang",98.5,563.5); 
	Student *pt=&stud1; 
	pt->display(); 
	grad1.display(); 
	return 0; 
} 

 
#include<iostream> 
using namespace std; 
#include<string.h> 
class employee 
{ 
protected: 
 char number[50]; 
 char name[30]; 
 char sexity[10]; 
 char position[30]; 
 double wage; 
 class Date 
 { 
 private: 
 static int year; 
 static int month; 
 static int day; 
 public: 
 Date() {} 
 static void SetYear(int _year) 
 { 
 year= _year; 
 } 
 static void SetMonth(int _month) 
 { 
 month = _month; 
 } 
 static void SetDay(int _day) 
 { 
 day = _day; 
 } 
 static int GetYear() 
 { 
 return year; 
 } 
 static int GetMonth() 
 { 
 return month; 
 } 
 static int GetDay() 
 { 
 return day; 
 } 
 }; 
public: 
 employee(char* number,char* name,char* sexity,char* position,int year,int month,int day) 
 { 
 strcpy(this->number,number); 
 strcpy(this->name,name); 
 strcpy(this->sexity,sexity); 
 strcpy(this->position,position); 
 Date::SetYear(year); 
 Date::SetMonth(month); 
 Date::SetDay(day); 
 } 
 employee(char* number="0",char* name="jiangwei",char* sexity="male",char* position="employee",int year=1994,int month=7,int day=28,double wage=0) 
 { 
 //number = new char[x]; ; 
 strcpy(this->number,number); 
 strcpy(this->name,name); 
 strcpy(this->sexity,sexity); 
 strcpy(this->position,position); 
 Date::SetYear(year); 
 Date::SetMonth(month); 
 Date::SetDay(day); 
 } 
}; 
int employee::Date::year = 0; 
int employee::Date::month = 0; 
int employee::Date::day = 0; 
class technician : public employee 
{ 
protected: 
 double worktime; 
public: 
 technician(char* number,char* name,char* sexity,char* position,double worktime,int year,int month,int day) 
 { 
 this->worktime=worktime; 
 } 
 void display() 
 { 
 wage=25*worktime; 
 cout<<"wage:"<<wage<<endl; 
 } 
}; 
void main() 
{ 
 technician p1("123456","weng","male","director",8,1994,7,28); 
 p1.display(); 
}  

 
#include<stdio.h>
#include<string.h>
int main()
{
int t3[4]={'0',0,'\0'};
printf("%d
",sizeof(t3));//16 printf("%d
",strlen((char*)t3));//1 }

좋은 웹페이지 즐겨찾기