Create a class template for a class that holds an object and the number of data
ID: 3561530 • Letter: C
Question
Create a class template for a class that holds an object and the number of data elements in the object. For example, if an Employee class has two data elements, an ID number and a salary, then the class template holds the number 2 and an Employee object; if a Student class contains 12 data elements, then the class template holds 12 and a Student. Code a standard input function for the object that displays a message on the screen such as: You will be asked to enter X items, where X is the number of data elements. Write a main() function that tests your template class with an integer and two programmer designed classes. Save the file as NumberOfFields.cpp.
Explanation / Answer
#include #include using namespace std; template class Employee{ private: T EmployeeID , EmployeeSalary; public: Employee( T theID , T theSalary ){ EmployeeID = theID; EmployeeSalary = theSalary; } }; template class Student{ private: public: T Student(){} }; int main(){ Employee theEmployee( 2 , 3000 ); Student theStudent (); system( "pause" ); return 0; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.