0% found this document useful (0 votes)
10 views5 pages

Assignment

The document contains multiple programming tasks in C, C++, and VB, including temperature conversion from Fahrenheit to Celsius, calculating monthly take-home pay with allowances and deductions, computing future value with interest, projecting membership fees with annual increases, displaying ordered pairs of numbers and their squares, and calculating squares and cubes of three user-input numbers. Each task is accompanied by sample code demonstrating the required functionality. The document serves as a guide for implementing these programming exercises.

Uploaded by

George Robinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Assignment

The document contains multiple programming tasks in C, C++, and VB, including temperature conversion from Fahrenheit to Celsius, calculating monthly take-home pay with allowances and deductions, computing future value with interest, projecting membership fees with annual increases, displaying ordered pairs of numbers and their squares, and calculating squares and cubes of three user-input numbers. Each task is accompanied by sample code demonstrating the required functionality. The document serves as a guide for implementing these programming exercises.

Uploaded by

George Robinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

2.

Write a program to convert Fahrenheit temperatures to Celsius and


Display the results. {Hint: = (F – 32) × 3⁄9}

#include <stdio.h>
int main(void)
{
int fahr;
int celsius;
printf("Enter a temperature in Fahrenheit: ");
scanf("%d", &fahr);
celsius = (fahr - 32)*3/9;
printf("The temperature in Celsius is %d\n", celsius);
return 0;
}

3. Write a program to calculate your monthly take-home pay considering


the following allowances and deductions on your basic salary
Allowances
Transport = 10% of your basic salary
Rent = 15% of your basic salary
Hazard = 6.5% of your basic salary
Deductions
Pension = 7.5%% of basic salary
NHIS = 5% of basic salary
Tax =2% of basic salary
[Hint: To calculate percentage of a number use (Amount x %)/100
#include <stdio.h>
int main()
{
float salary, transport_allowance, rent_allowance, hazard_allowance,
pension_deduction, nhis_deduction, tax_deduction, total_allowance, total_deduction,
take_home_pay;
printf("Enter your basic salary: ");
scanf("%f", &salary);
transport_allowance = (salary * 10) / 100;
rent_allowance = (salary * 15) / 100;
hazard_allowance = (salary * 6.5) / 100;
pension_deduction = (salary * 7.5) / 100;
nhis_deduction = (salary * 5) / 100;
tax_deduction = (salary * 2) / 100;
total_allowance = transport_allowance + rent_allowance + hazard_allowance;
total_deduction = pension_deduction + nhis_deduction + tax_deduction;
take_home_pay = salary + total_allowance - total_deduction;
printf("Your take-home pay is: %.2f", take_home_pay);
}

4. Given initial amount and a yearly Interest rate calculate the amount of
money expected at the end of a period of not less than 5 years Assume
n=
Hint: A = P(1+r⁄n)nt
A=Amount of money expected
P=Initial amount
R=Interest Rate in percent
R=R/100
T=Time involved in years. 0.5 years is calculated as 6 months, etc.
A = P(1+r⁄n)nt
A = P(1+ (R/100)/n)nt
For example, if the initial amount is N100,000 and the yearly interest rate is 10%, and
the period is 5 years, the expected amount is N146,744.
A = 100,000(1 + (10/100)/1)5
A = 100,000(1.10)5
A = 146,744

5. A country club, which currently charges N25,000.00 per year for


membership has announced it will increase its membership fee by 4%
each year for the next 6 years. Write a program that uses a loop to
display the project for the next six years.

#include <iostream>
int main()
{
double fee = 25000;
std::cout << "Year\t\tMembership Fee" << std::endl;
for (int year = 1; year <= 6; year++)
{
fee += fee * 0.04;
std::cout << year << "\t\t" << fee << std::endl;
}
return 0;
}
6. Write a program that should take two numbers (that is, first and last)
from the user and display all the numbers and their square in the form
of an ordered pair between the first and last numbers. For example, if a
user enters 2 to 5 then it should display pairs: (2.4) (3.9) (4.16) 15.25)

#include <iostream>
using namespace std;
int main()
{
int startnum, endnum;
cout << "Please enter two numbers (first and last): ";
cin >> startnum >> endnum;
for (int i = startnum; i <= endnum; i++){
cout << "(" << i << "," << i*i << ")" << endl;
}
7. Write a program in VB that should take 3 numbers from the user as input. Your
program should find and print the square and cube of these three numbers on the
screen.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Declare the three variables to store the input numbers
Dim num1, num2, num3 As Integer
'Read the three numbers from the user
num1 = TextBox1.Text
num2 = TextBox2.Text
num3 = TextBox3.Text
'Calculate the squares and cubes of the three numbers
Dim square1, square2, square3, cube1, cube2, cube3 As Integer
square1 = num1 * num1
square2 = num2 * num2
square3 = num3 * num3
cube1 = num1 * num1 * num1
cube2 = num2 * num2 * num2
cube3 = num3 * num3 * num3
'Print the results
MessageBox.Show("Square of " & num1 & " is " & square1 & vbCrLf & "Square of "
& num2 & " is " & square2 & vbCrLf & "Square of " & num3 & " is " & square3 &
vbCrLf & "Cube of " & num1 & " is " & cube1 & vbCrLf & "Cube of " & num2 & "
is " & cube2 & vbCrLf & "Cube of " & num3 & " is " & cube3)
End Sub
End Class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy