Tuesday, 22 March 2016

B1: Conversion of If-else ladder to overloaded function

Q: You are required to write a C program involving a if-then-else construct and convert it into a C++ program eliminating the if-then-else ladder using overloaded functions.

Text Editor:-Gedit
Language:- C,C++
Framework:- QT(C++)
OS:- Linux-64bit (Fedora)




C code to convert




#include <stdio.h>
#include <stdlib.h>

int salcal(char choice,float sal){
printf("Your entered salary is %0.2f",sal);
if(choice=='p'){
printf("\nYour Daily allowance is \t%0.2f",sal*0.15);
printf("\nYour House Raint allowance is \t%0.2f",sal*0.20);
printf("\nYour Total Gross Salary is \t%d",(int)(sal*1.35));
}
else{
printf("\nYour Daily allowance is \t%0.2f",sal*0.15);
printf("\nYour Total Gross Salary is \t%d\n",(int)(sal*1.15));
}

}

int main(){
printf("Enter your post\n president/manger (p/m)");
char choice;
scanf("%c",&choice);
puts("Enter your basic salary");
float sal,hra,da;
scanf("%f",&sal);
salcal(choice,sal);
return 0;
} 



Screenshot for C++ Program




All related files to this project available at :-mediafire

source codes, executables and screenshot

No comments:

Post a Comment