Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The program in C++ below asks for name, salary, and ID . How can I restrict the ID will be entered by the user to

The program in C++ below asks for name, salary, and ID. How can I restrict the ID will be entered by the user to 4 digits only?

NOTE: I WANT TO KEEP ID TYPE AS INTEGER. I NEED THE SIMPLIEST SOLUTION WITH MINIMAL CHANGE WITHIN THE ENTIRE PROGRAM.

INCOMPLETE OR WRONG ANSWERS WILL GET NEGATIVE VOTES!

THANK YOU.

// PROGRAM STARTS HERE

#include using namespace std; class EMPLOYEE//class definition {//private data members private: string name; double salary; int ID; public:

//default constructor EMPLOYEE(): name(""), salary(0.0), ID(0){} //getter methods for private data members string getName() { return name; } double getSalary() { return salary; } int getID() { return ID; } //setter methods for fata members void setName(string n) { name = n; } void setSalary(double s) { salary = s; } void setID(int i) { ID = i; } }; int main() { EMPLOYEE e1;//create instance of employee string name; double salary; int id; //take input for data members cout << "Enter name of Employee: "; getline(cin,name); cout << "Enter salary of Employee: "; cin >> salary; cout << "Enter ID of Employee: "; cin >> id; //set values for data members e1.setID(id); e1.setName(name); e1.setSalary(salary);

//print details entered using getter methods printf("Details entered for the employee: ID = %d, Name: %s, Salary: %.2f", e1.getID(), e1.getName().c_str(), e1.getSalary()); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

Students also viewed these Databases questions

Question

Define the goals of persuasive speaking

Answered: 1 week ago