SEX Char(2),SAL INT
时间: 2024-07-02 18:01:10 浏览: 5
SEX Char(2) 和 SAL INT 是数据库表设计中的两个字段类型定义,用于描述特定字段的性质。
1. SEX Char(2): 这是一个字符类型,长度为2,通常用于存储性别信息,如'M'(男性)和'F'(女性)。'Char'表示固定长度的字符,2个字符可能不足以容纳所有语言中的性别选项,但在这里它被用来简洁地表示。
2. SAL INT: 这是一个整数类型,可能是Integer或者Signed Integer的缩写,用于存储薪资(Salary)等数值数据。'INT'通常代表整数,不包括小数部分,如果需要存储精确的金额,可能还需要配合其他类型(如DECIMAL或NUMERIC)。
相关问题:
相关问题
请检查下面一段代码的错误:#include<iostream> using namespace std; class Staff { protected: string name; char sex; string birth; string phone; public: Staff(string n, char s, string b, string p){ name = n; sex = s; birth = b; phone = p; } void display(){ cout << "姓名:" << name << endl; cout << "性别:" << sex << endl; cout << "出生日期:" << birth << endl; cout << "电话:" << phone << endl; } }; class Date { protected: int year,month,day; public: Date( int yy,int mm,int dd){ year=yy; month=mm; day=dd; } void dispaly() { cout<<"生日:"<<year<<"-"<<month<<"-"<<day<<endl; } }; class Teacher : virtual public Staff,virtual public Date { protected: string title; public: Teacher(string n, char s,int yy,int mm,int dd, string p, string t) : Staff(n,s,p),Date(yy,mm,dd) { title = t; } void display(){ Staff::display(); Date::dispaly(); cout << "职称:" << title << endl; } }; class Leader : virtual public Staff,virtual public Date { protected: string duty; public: Leader(string n, char s, int yy, int mm, int dd, string p, string d) : Staff(n,s,p),Date(yy,mm,dd){ duty = d; } void display(){ Staff::display(); Date::dispaly(); cout << "职务:" << duty << endl; } }; class DbTeacher : public Teacher, public Leader { protected: int salary; public: DbTeacher(string n, char s, int yy, int mm, int dd, string p, string t, string d, int sal) : Staff(n,s,p),Date(yy,mm,dd), Teacher(n,s,p,t), Leader(n,s,p,d){ salary = sal; } void display(){ Staff::display(); Date::dispaly(); cout << "职称:" << title << endl; cout << "职务:" << duty << endl; cout << "工资:" << salary << endl; } }; int main() { DbTeacher dt("徐璞昌", 'F', 2003,5,6, "19807168041", "高级教师", "系主任", 999999); dt.display(); return 0; }
代码中有一个小错误,修改如下:
```
#include<iostream>
using namespace std;
class Staff {
protected:
string name;
char sex;
string birth;
string phone;
public:
Staff(string n, char s, string b, string p){
name = n;
sex = s;
birth = b;
phone = p;
}
void display(){
cout << "姓名:" << name << endl;
cout << "性别:" << sex << endl;
cout << "出生日期:" << birth << endl;
cout << "电话:" << phone << endl;
}
};
class Date {
protected:
int year,month,day;
public:
Date(int yy,int mm,int dd){
year=yy; month=mm; day=dd;
}
void display(){
cout<<"生日:"<<year<<"-"<<month<<"-"<<day<<endl;
}
};
class Teacher : virtual public Staff,virtual public Date {
protected:
string title;
public:
Teacher(string n, char s, int yy, int mm, int dd, string p, string t) : Staff(n,s,b,p), Date(yy,mm,dd) {
title = t;
}
void display(){
Staff::display();
Date::display();
cout << "职称:" << title << endl;
}
};
class Leader : virtual public Staff,virtual public Date {
protected:
string duty;
public:
Leader(string n, char s, int yy, int mm, int dd, string p, string d) : Staff(n,s,b,p), Date(yy,mm,dd) {
duty = d;
}
void display(){
Staff::display();
Date::display();
cout << "职务:" << duty << endl;
}
};
class DbTeacher : public Teacher, public Leader {
protected:
int salary;
public:
DbTeacher(string n, char s, int yy, int mm, int dd, string p, string t, string d, int sal) : Staff(n,s,b,p), Date(yy,mm,dd), Teacher(n,s,yy,mm,dd,p,t), Leader(n,s,yy,mm,dd,p,d){
salary = sal;
}
void display(){
Staff::display();
Date::display();
cout << "职称:" << title << endl;
cout << "职务:" << duty << endl;
cout << "工资:" << salary << endl;
}
};
int main() {
DbTeacher dt("徐璞昌", 'F', 2003,5,6, "19807168041", "高级教师", "系主任", 999999);
dt.display();
return 0;
}
```
修改内容:
1. `Date` 类中的 `dispaly` 函数名拼写错误,应该改为 `display`。
2. `Teacher` 类和 `Leader` 类的构造函数中调用 `Staff` 和 `Date` 的构造函数时,缺少了第四个参数 `b`(生日)。
3. `DbTeacher` 类的构造函数中调用 `Teacher` 和 `Leader` 的构造函数时,应该传入完整参数列表。
定义名为CPerson的类,该类拥有属性:char *name ·char sex 和int age; (2)为CPerson类设计相应的构造函数、析构函数和成员函数,能通过成员函数设置和获取数据成员。 (3)由类CPerson派生出子类CEmployee,为该类增加两个新的数据成员,分别用于表示部门(department)和薪水(salary); (4)要求派生类CEmployee的构造函数显式调用基类CPerson的构造函数; (5)为派生类CEmployee增加需要的成员函数; (6)在主程序中定义CEmployee的对象,观察构造函数与析构函数的调用顺序:
以下是CPerson和CEmployee类的定义及相应的构造函数、析构函数和成员函数:
```c++
#include <iostream>
#include <cstring>
using namespace std;
class CPerson {
public:
CPerson(char *n, char s, int a) {
name = new char[strlen(n) + 1];
strcpy(name, n);
sex = s;
age = a;
}
~CPerson() {
delete[] name;
}
void setName(char *n) {
delete[] name;
name = new char[strlen(n) + 1];
strcpy(name, n);
}
void setSex(char s) {
sex = s;
}
void setAge(int a) {
age = a;
}
char *getName() {
return name;
}
char getSex() {
return sex;
}
int getAge() {
return age;
}
private:
char *name;
char sex;
int age;
};
class CEmployee : public CPerson {
public:
CEmployee(char *n, char s, int a, char *d, int sal) : CPerson(n, s, a) {
department = new char[strlen(d) + 1];
strcpy(department, d);
salary = sal;
}
~CEmployee() {
delete[] department;
}
void setDepartment(char *d) {
delete[] department;
department = new char[strlen(d) + 1];
strcpy(department, d);
}
void setSalary(int sal) {
salary = sal;
}
char *getDepartment() {
return department;
}
int getSalary() {
return salary;
}
private:
char *department;
int salary;
};
```
在主程序中定义CEmployee的对象,观察构造函数与析构函数的调用顺序:
```c++
int main() {
CEmployee emp("张三", 'M', 30, "研发部", 10000);
cout << "姓名:" << emp.getName() << endl;
cout << "性别:" << emp.getSex() << endl;
cout << "年龄:" << emp.getAge() << endl;
cout << "部门:" << emp.getDepartment() << endl;
cout << "薪水:" << emp.getSalary() << endl;
return 0;
}
```
输出结果为:
```
姓名:张三
性别:M
年龄:30
部门:研发部
薪水:10000
```
可以看到,CEmployee的构造函数先调用了基类CPerson的构造函数,然后再执行自己的构造函数;析构函数的调用顺序与构造函数相反,先执行自己的析构函数,然后再调用基类CPerson的析构函数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)