c++ program, please include all details program1) Create a function template to
ID: 657143 • Letter: C
Question
c++ program, please include all details
program1) Create a function template to display a value that is both preceded and followed by 10
asterisks on a line. Write a main()function that tests the function with character, integer,
double, and string arguments.
//***************************************************
program 2) Create an Employee class that contains three data fields of your choice. Include a
constructor to set the data values and an overloaded insertion operator that displays
the data fields. Write a main()function that demonstrates the template that displays the
preceding and trailing asterisks and also works with an Employee argument.
Explanation / Answer
template< class T , class U ,class X >
void Printoutput( T value ,U elements , X timesRepeated ){
for( int i = 0 ; i < timesRepeated ; i++ )
cout << elements ;
cout << value;
for( int i = 0 ; i < timesRepeated ; i++ )
cout << elements;
cout << endl;
}
int main(){
Printoutput(47,'*',3);
Printoutput(39.25,0,3);
Printoutput("Bob",'a',4);
system( "pause" );//system pause
return 0;//Exit program
}
#include<iostream.h>
#include<conio.h>
class employee
{
int emp_num;
char emp_name[20];
float emp_basic;
float sal;
float emp_da;
float net_sal;
float emp_it;
public:
void get_details();
void find_net_sal();
void show_emp_details();
};
void employee :: get_details()
{
cout<<" Enter employee number: ";
cin>>emp_num;
cout<<" Enter employee name: ";
cin>>emp_name;
cout<<" Enter employee basic: ";
cin>>emp_basic;
}
void employee :: find_net_sal()
{
emp_da=0.52*emp_basic;
emp_it=0.30*(emp_basic+emp_da);
net_sal=(emp_basic+emp_da)-emp_it;
}
void employee :: show_emp_details()
{
cout<<" Details of : "<<emp_name;
cout<<" Employee number: "<<emp_num;
cout<<" Basic salary : "<<emp_basic;
cout<<" Employee DA : "<<emp_da;
cout<<" Income Tax : "<<emp_it;
cout<<" Net Salary : "<<net_sal;
}
int main()
{
employee emp[10];
int i,num;
clrscr();
cout<<" Enter number of employee details ";
cin>>num;
for(i=0;i<num;i++)
emp[i].get_details();
for(i=0;i<num;i++)
emp[i].find_net_sal();
for(i=0;i<num;i++)
emp[i].show_emp_details();
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.