SECJ1013 - Programming Technique 1

This course will equip students with the theory and practice of problem-solving techniques using a structured approach. Students are required to develop programming using C++ programming language to solve simple to moderate problems.

2Q==

Tax Payable

#include <iostream>

using namespace std;

int main()
{
char residentstatus, answer = 'y';
int annualincome, taxpayable, netincome;

do{
cout << "Resident status (R or N): ";
cin >> residentstatus;

if (residentstatus == 'R'){

cout << "Annual income: ";
cin >> annualincome;

if (annualincome >= 0 && annualincome <= 20000){
taxpayable = annualincome * 0;
netincome = annualincome - taxpayable;
} else if (annualincome > 20000 && annualincome <= 50000){
taxpayable = annualincome * 0.11;
netincome = annualincome - taxpayable;
} else if (annualincome > 50000 && annualincome <= 80000){
taxpayable = (0.11 * 50000) + (0.15 * (annualincome - 50000));
netincome = annualincome - taxpayable;
} else if (annualincome > 80000){
taxpayable = (0.11 * 50000) + (0.15 * (30000)) + (0.2 * (annualincome - 80000));
netincome = annualincome - taxpayable;
} else {
cout << "Invalid input. Please insert input between the range." << endl;
}

cout << "Tax payable: " << taxpayable << endl;
cout << "Net income: " << netincome << endl;

} else if (residentstatus == 'N'){
cout << "Annual income n: ";
cin >> annualincome;

if (annualincome >= 0 && annualincome <= 50000){
taxpayable = annualincome * 0.2;
netincome = annualincome - taxpayable;
} else if (annualincome > 50000 && annualincome <= 80000){
taxpayable = (0.2 * 50000) + (0.22 * (annualincome - 50000));
netincome = annualincome - taxpayable;
} else if (annualincome > 80000){
taxpayable = (0.2 * 50000) + (0.22 * (30000)) + (0.24 * (annualincome - 80000));
netincome = annualincome - taxpayable;
}

cout << "Tax payable: " << taxpayable << endl;
cout << "Net income: " << netincome << endl;
} else {
cout << "Invalid input. Please follow the example given." << endl;
}

cout << endl;
cout << "Do you want to continue? Answer y for yes and n for no: ";
cin >> answer;
cout << endl;
} while (answer == 'y' || answer == 'Y');


return 0;
}

Output:

Screenshot (98).png

Counting Tile

#include <iostream>

using namespace std;

int getTileWidth(int);
int getTileLength(int);
int getTileArea(int, int);
double getSurfaceArea(int, int);
int getTotalTile(double, int);

int main()
{
int tileCode, tileWidth, tileLength, tileArea;
int surfaceWidth, surfaceLength;
double surfaceArea;
int totalTile;

cout << "Enter tileCode: ";
cin >> tileCode;

cout << "Enter surface width in Feet: ";
cin >> surfaceWidth;

cout << "Enter surface length in Feet: ";
cin >> surfaceLength;

cout << endl;

tileWidth = getTileWidth(tileCode);
cout << "Tile width in inches: " << tileWidth << endl;

tileLength = getTileLength(tileCode);
cout << "Tile length in inches: " << tileLength << endl;

tileArea = getTileArea(tileLength, tileWidth);
cout << "Tile area in inches square: " << tileArea << endl;

cout << endl;

surfaceArea = getSurfaceArea(surfaceLength, surfaceWidth);
cout << "Surface area in inches square: " << surfaceArea << endl;

cout << endl;

totalTile = getTotalTile(surfaceArea, tileArea);
cout << "Total tile needed: " << totalTile << endl;

return 0;
}

int getTileWidth(int tileCode){
int TileWidth;
return TileWidth = tileCode / 100;
}

int getTileLength(int tileCode){
int TileLength, tileWidth;
tileWidth = getTileWidth(tileCode);
return TileLength = tileCode - (tileWidth * 100);
}

int getTileArea(int tileLength, int tileWidth){
int tileArea;
return tileArea = tileWidth * tileLength;
}

double getSurfaceArea(int surfaceLength, int surfaceWidth){
double surfaceArea;
cout << "Surface width in Feet: " << surfaceWidth << endl;
cout << "Surface length in Feet: " << surfaceLength << endl;

return surfaceArea = (surfaceWidth * 12) * (surfaceLength * 12);
}

int getTotalTile(double surfaceArea, int tileArea){
int tileCount;
return tileCount = surfaceArea / tileArea;
}

Output:

Screenshot (94).png

Hospital Billing Statement

#include<iostream>

using namespace std;

int main()
{
char answer = 'n';
int days;
char room, tv, wifi;
float roomcharges, tvcharges, wificharges, total;

do{
cin >> days >> room >> tv >> wifi;

if (room == 'F'){

roomcharges = 265 * days;
} else if (room == 'S'){

roomcharges = 230 * days;
} else if (room == 'T'){

roomcharges = 120 * days;
}

if (tv == 'Y'){

tvcharges = 10 * days;
} else if (tv == 'N'){

tvcharges = 0 * days;
}

if (wifi == 'Y'){

wificharges = 5 * days;
} else if (wifi == 'N'){

wificharges = 0 * days;
}

total = roomcharges + tvcharges + wificharges;

cout << " _____________________________________________________" << endl;
cout << " |\t\t\t SABY HOSPITAL\t\t\t|";
cout << "\n |\t\t Patient Billing Statement\t\t|" << endl;
cout << " |\tNumber of days warded: " << days<< "\t\t\t|" << endl;
cout << " |\tRoom class: " << room << "\t\t\t\t\t|"<< endl;
cout << " |\t\t\t\t\t\t\t|" << endl;
cout << " |\tRoom charges \t\t\t\t RM" << roomcharges << " |" << endl;
cout << " |\tTelevision charges \t\t\t RM" << tvcharges << " |" << endl;
cout << " |\tWIFI charges \t\t\t\t RM" << wificharges << " |" << endl;
cout << " |\t\t\t\t\t\t\t|" << endl;
cout << " |\tTOTAL DUE \t\t\t\t RM" << total << " |" << endl;
cout << " |\t\t\t\t\t\t\t|" << endl;
cout << " |___________________________________________________|" << endl;

cout << endl;
cout << "Do you want to stop: ";
cin >> answer;
cout << endl;
} while(answer == 'n');

return 0;
}

Output:

Screenshot (96).png

Length Convertor

#include <iostream>

using namespace std;

void FeetToInches();
void InchesToCentimeters();
void CentimetersToMeters();

int main()
{
int choice;

do{
cout << "\nOPTION\t\tOPERATION" << endl;
cout << " 1\tConvert from feet to inches" << endl;
cout << " 2\tConvert from inches to centimeters" << endl;
cout << " 3\tConvert from centimeters to meters" << endl;
cout << " 4\tExit" << endl << endl;

cin >> choice;

switch (choice)
{
case 1: FeetToInches();
break;
case 2: InchesToCentimeters();
break;
case 3: CentimetersToMeters();
break;
case 4: cout << "\nThank you for using our system..." << endl;
exit(1);
default:cout << "\nInvalid input" << endl;
exit(1);
}
} while (choice != 4);


return 0;
}

void FeetToInches()
{
double feet, inches;

cout << "Enter feet: ";
cin >> feet;
inches = feet * 12;
cout << "Inches: " << inches << endl;
}

void InchesToCentimeters()
{
double inches, centimeters;

cout << "Enter inches: ";
cin >> inches;
centimeters = inches * 2.54;
cout << "Centimeters: " << centimeters << endl;
}

void CentimetersToMeters()
{
double centimeters, meters;

cout << "Enter centimeters: ";
cin >> centimeters;
meters = centimeters / 100;
cout << "Meters: " << meters << endl;
}

Output:

Screenshot (100).png