怎么解决这个程序? [英] How to solve this program?

查看:98
本文介绍了怎么解决这个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:指示在setvalue函数中从user获取值,然后在此程序中使用重载构造函数是什么?



您需要实现员工管理系统。将有一个具有以下属性的雇员类:Name(String),Father_Name(String),Emp_id(int),dob(日期),bps(1-22),job_Type(私有,公共或自治)它应该有两个构造函数即,默认构造函数和重载的构造函数。必须通过初始化列表初始化构造函数中的属性。 Employee类应具有以下功能,即setRecord和showRecord。在setEmployeeRecord中,数据输入应该来自用户,而showRecord应该打印员工的详细信息。



我尝试过:



我试过但是它给出了以下错误。

1.输入'int'意外

2.'emp_id ':未声明的标识符

3.'bps':未声明的标识符



Problem: It is instructed that take the value from user in setvalue function then what is the use of overloaded constructor in this program?

You are required to implement Employee Management System. There will be an employee class having following attributes: Name(String), Father_Name(String), Emp_id(int), dob(date), bps(1-22), job_Type(Private, public or autonomous) It should have two constructors i.e., default constructor and an overloaded constructor. The attributes in the constructors must be initialized through initializer list. The Employee class should be having following functions i.e., setRecord and showRecord. In the setEmployeeRecord, the data input should be taken from the user while showRecord should print the employee details.

What I have tried:

I tried but it give following error.
1. type 'int' unexpected
2. 'emp_id': undeclared identifier
3. 'bps': undeclared identifier

#include<iostream>
#include<string>
using namespace std;
class Employee 
{
	string name;
	string father_name;
	int emp_id;
	string date;
	int bps;
	string job_Type;
public:
	Employee();
	Employee(string nam, string f_name, int id, string dt, int b, string job) :name(nam), father_name(f_name), emp_id(id), bps(b), job_Type(job) {}
	void setRecord(string nam, string f_name, int id, string dt, int b, string job);
	void showRecord();
};
Employee::Employee() { /*cout << "Default Constructor" << endl;*/ }
void Employee::setRecord(string nam, string f_name, int id, string dt, int b, string job)
{
	cout << "Name of Employee: ";
	cin >> nam;
	cin.ignore();
	cout << "Father Name: ";
	cin >> f_name;
	cout << "Employee ID: ";
	cin >> id;
	cout << "Date of Birth: ";
	//cin.ignore();
	cin >> dt;
	cout << "Basic Pay Scale: ";
	cin >> b;
	cout << "Job Type: ";
	cin.ignore();
	cin >> job;
}
void Employee::showRecord()
{
	cout << "Name: " << name << endl;
	cout << "Father Name: " << father_name << endl;
	cout << "Employee ID: " << emp_id << endl;
	cout << "Date of Birth: " << date << endl;
	cout << "Basic Pay Scale: " << bps << endl;
	cout << "Job Type: " << job_Type << endl;
}

int main()
{
	string nam, f_name, job, dt,
	int id, b;
	Employee A;
	A.setRecord(nam, f_name, id, dt, b, job);
	system("pause");
	return 0;
}

推荐答案

重载构造函数的目的是为您提供两种构造对象的方法。您可以将其初始化为默认值,也可以使用特定值构建它。
The purpose of the overloaded constructor is to give you two ways to construct the object. You can either have it initialized to default values or you can construct it with specific values.


将Employee类写入额外文件中,在header(employee.h)和实现(employee)中分隔。 cpp)文件。这是编码的标准。



提示:在默认构造函数中,你必须也将值设置为成员。像那样:

Write the Employee class in extra files, separated in header (employee.h) and implemention (employee.cpp) files. It is standard in coding to do this.

tip: in the default constructor you MUST also set the values to the member. Like that:
Employee():name(""), father_name(""), emp_id(0), bps(0), job_Type("") {} 



SetRecord错误。用对象的成员重写函数。


The SetRecord is wrong. Rewrite the function with the members of the object.

void Employee::setRecord()
{
	cout << "Name of Employee: ";
	cin >> name;//correct, but some like more typing with "this->name" !!!


您可以查看我的代码,告诉我代码中的错误。
can you review my code to tell me what is error in my code.


这篇关于怎么解决这个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆