You are on page 1of 7

Homework No.

3
Name: Paz, Jose Gabriel L.
Student No.: 2018151107
Course: ECE-1 Subject & Section: CPE103-1L -A12
Date: 12/17/18

1. Complete the program below using functions. All you have to do is fill in the functions with
the proper codes and methods to make the program compute for the Take Home Amount.
Make use of the predefined values. It must also display the breakdown of the computation as
follows,

Note: For your final output, number of hours worked is 12 as shown in the illustration above.
(10 pts)

#include<iostream>

using namespace std;

double Hours_Worked()
{

void Display_Earnings(double)
{
const double Rate = 5.00;
const double Deduction = 10.00;
//To compute for taxes due, it will be (Total Earnings x 32%).

//Code goes here…


//Number of hours will be passed as argument/parameter from main()…
//Function will display the breakdown of the take home pay…
}

int main()
{
//Code goes here…
//main() will call Hours_Worked() to get the number of hours worked…
//main() will pass the number of hours worked to Display_Earnings()…
}

Source Code & Output:


#include<iostream>
using namespace std;
double Hours_Worked()
{
double Hrs;
cout << "\nEnter the number of hours worked: ";
cin >> Hrs;
return Hrs;
}
void Display_Earnings(double Hrs)
{
const double Rate = 5.00;
const double Deduction = 10.00;
double Total_Earnings, Tax, Amount_Paid;

Total_Earnings = Hrs * Rate;


Tax = (Hrs*Rate)*0.32;
Amount_Paid = Total_Earnings - Tax - Deduction;

cout << "\nTotal Earnings: $" << Hrs * Rate << endl;
cout << "Taxes Due: $" << Tax << endl;
cout << "Deductions: $" << Deduction << endl;
cout << "Take Home Amount: $" << Amount_Paid << endl << endl;
}
int main()
{
int Hrs;
Hrs = Hours_Worked();
Display_Earnings(Hrs);
return 0;
}
2. Complete the following program using functions and structure. Fill in the missing code and the
program should be able to ask for the employee ID and employee name as follows,

Note: For your final output, use your student number for Employee ID and your full name as
Employee’s Name. Make sure your full name is displayed on the output. (10 pts)

#include<iostream>
#include<string>

using namespace std;

struct Employee
{
//Code goes here…
};

int main()
{
//Code goes here…
//main() will call Get_Employee_Data() and store the returned structure.
//main() will call Display_Employee_Data and pass the structure to display
employee information…
}

Employee Get_Employee_Data()
{
//Code goes here…
//This function will store the employee details and return the structure to
main()…
}

void Display_Employee_Data(Employee)
{
//Code goes here…
//Structure will be passed from main()…
//This function will display the employee details…
}

Source Code & Output:

#include<iostream>
#include<string>
using namespace std;
struct Employee
{
int ID;
string Name;
};
int main()
{
Employee The_Employee;
Employee Get_Employee_Data();
void Display_Employee_Data(Employee);
The_Employee = Get_Employee_Data();
Display_Employee_Data(The_Employee);

return 0;
}
Employee Get_Employee_Data()
{
Employee The_Employee;

cout << "\nEnter the Employee ID: ";


cin >> The_Employee.ID;
cout << "\nEnter Employee's Name: ";
cin.ignore();
getline(cin, The_Employee.Name);

return The_Employee;
}
void Display_Employee_Data(Employee The_Employee)
{
cout << "\n\nEmployee ID: " << The_Employee.ID << endl;
cout << "Employee's Name: " << The_Employee.Name << endl << endl;
}

3. Complete the program below using functions, pointers, addresses. Fill in the missing code and
the program should ask for student details and display it as follows,
Note: For your final output, use your student number and make sure your full name is
displayed. (10 pts)
#include<iostream>
#include<string>

using namespace std;

int main()
{
//Code goes here…
//main() passes references of Student ID and Student Name to Get_Student_Details
to be initialized…
//main() passes references of Student ID and Student Name to
Display_Student_Details to display student information…
}

void Get_Student_Details(int *, string *)


{
//Code goes here…
//main() will pass the reference values of Student ID and Student Name.
//Function will store entered values to these references.
}

void Display_Student_Details(int *, string *)


{
//Code goes here…
//main() will pass the reference values of Student ID and Student Name to be
displayed.
}

Source Code & Output:

#include<iostream>

#include<string>

using namespace std;

int main()

int Student_ID;

string Student_Name;

void Get_Student_Details(int *, string *);

void Display_Student_Details(int *, string *);

Get_Student_Details(&Student_ID, &Student_Name);

Display_Student_Details(&Student_ID, &Student_Name);

return 0;
}

void Get_Student_Details(int *Student_ID, string *Student_Name)

cout << "\nEnter your Student Number: ";

cin >> *Student_ID;

cout << "\nEnter your full name: ";

cin.ignore();

getline(cin, *Student_Name);

void Display_Student_Details(int *Student_ID, string *Student_Name)

cout << "\n\nStudent Number: " << *Student_ID << endl;

cout << "Student Name: " << *Student_Name << endl << endl;

You might also like