University of Education, Faisalabad Campus
ASSIGNMENT
Submitted to: Dr. Muhammad Anwar
Submitted by: Muhammad Awais Mahmood
Course Title: | Programming Fundamentals
Roll No: bsf23005127
Course Code: COMP 1112
Program: BS Computer Science
Semester: 1% Morning BTable of Contents for Assignment
| Q.No. | Description Page
No.
Q.NO | Write a program to that can take three numbers as input from
1 the user and find the maximum number among them. A
Q.NO | Write a program which ask the user to enter a positive integer and]
| 2 then calculate its factorial. 4
|
Q.NO | Write a program to count total number of currency notes of 5
3 5000, 1000, 500, 100, 50, 20 and 10 in a given amount.
Q.NO | Write a program to input electricity unit consumed and calculate
4 total electricity bill according to the given condition:
* Ifnumber of units are up to 100, the bill will be charged
at the rate of Rs. 5 per unit
+ Ifnumber of units are up to 200, the bill will be charged
at the rate of Rs. 10 per unit 6
* Ifnumber of units are above 200, the bill will be charged
at the rate of Rs. 20 per unit
Q.NO | Write a program to design ATM interface to perform the
5 following transactions. You may initialize the balance with zero.
After cach transaction, the program should ask the user to
perform another transaction. Based on the input (y/n) the
program either redirects to the main interface or exit.
+ Press B to check account Balance 7
= Press D to cash Deposit
«Press W to cash WithdrawWrite a program to that can take three numbers as
input from the user and find the maximum number among
them.
#include
using namespace std;
int main() {
int num4, num2, num3;
cout<<"awais mahmood:’<> num4 >> num2 >> num3;
int max_number = (num4 > num2) ? (num4 > num3 ? num4: num3) : (num2 >
num3 ? num2 : num3);
cout << “The maximum number is:"<< max_number<< endl;
cout<<"awais Mahmoox
return 0; —
ite everday mEQ. NO 2:
Write a program which ask the user to enter a
positive integer and then calculate its factorial.
#include
using namespace std;
int main() {
int num;
cout<<"awais mahmoo
cout<<"enter a positive integer:
cin>>num;
if(num<0) (
cout<<"Please enter a positive integer.”<
using namespace std.
int main()
(
int amount;
int notes[7]= (5000, 1000, 500, 100, 50, 20, 10};
int counts[7]=(0};
cout<<"awais mahmood:";
cout<<"enter the amount:";
cin>> amount; ‘
for (int i=0;i<73i++) (
if (amount >=notes{i])
(
counts[i] = amount / notes[i];
amount% = notes|i:
}
for (int i=0; i<7; i++)If (counts[i] > 0) {
cout << “Number of" << Notes[i}<<"
<"notes:"<
‘
Using namespace std;
int main()jnt units;
double bill = 0;
cout <<"enter the number of y
Ss nits
aon . consumeg:”.
if(units<=100) {
bill = units*5;
}
else if(units<=200)t
bill = 100 * 5 + (units
~ 100) * 10;
; ) * Lo;
else (
bill = 100 * 5 +400*
10 + (uni
: (units - 200)*20;
Cout <<’Total electrici
ticity bill; Rs."<
using namespace std;
int main()
( a
char choice;
double balance = 0;
do {
cout<<"Press B to check account balan;
cout<<” Press D to deposit cash ,
cout<<"Press W to withdraw cas|
cout<<"Enter your choice;";
cin>>choice;
switch (choice) {
Ce.” << endl;
” << endl;
h.<< endl;
Sout<<"Your account balance is: $” <>deposit;
balance += deposit;
dl;
is :$"<< balance<< endl;
Cout<< "Deposit successful. Your new balance is
break:
Case'wr,case W's
gouble withdraw:
couts<"Enter the amount to withdraw: 3";
inp >withdraw:
i¢qwithdraw > balance) {
cout <> choice;
}
while (choice ="
cout<<” Thank
return 0;
A
“Do you want to perform another transaction? (y/ny"5
A
=):
you for using our ATM. Have Anice
Y’| | choice
day!"<
double findMaximum(double num1, double num2, double num3) {
return std::max(std::max(num1, num2), num3);
}
int main() {
double num1, num2, num3;
std::cout << "Enter the first number: ";
std::cin >> nur;
std::cout << "Enter the second number: ";
std::cin >>nam2;
out << "Enter the third number: ";
std::cin >> num3;
double maximumNumber = findMaximum(num1, num2, num3);
std::cout << "The maximum number among "<< num << ","<
// Function to calculate the factorial of a number
ong long calculateFactorial(int n) {
if(n == 0 |] n== D4
return 1;
pelse {
return n * calculateFactorial(n - 1);
}
3
~~ int main0 {
// Taking input from the user
int number;
std::cout << "Enter a pos! ‘ive integer: ";
std::cin >> number;
// Checking if the number is non-negativeASSIGNMES" \
or
void countCurrencyNotes(int
nominations[] = {5000, 1000, 500, 100, 50, 20, 10};
int notesCount[7] = {0};
amount) {
int det
for(inti= 051 <7; 441) {
hotesCountti] = amount / denominations[i];Amount %= denominations[i];
}
// Displaying the result
for (inti = 0; i< 7; ++i) {
if (notesCount{i] > 0) {
Std::cout << "Number of " << denominations[i] <<" notes: " <<
notesCount[i] << std::endl;
}
}
}
int mainQ {
int amount;
std::cout << "Enter the amount:
std::cin >> amount;
// Checking if the amount is non-negative
if (amount < 0) {
std::cerr << "Error: Please enter a non-negative amount." << std::endl;
return 1; // Returning 1 to indicate an error
}
// Calculating and displaying the currency notes
countCurrencyNotes(amount);
return 0;
CHa NES Taree NTN)Program 4 at
Write a program to input electricity unit consumed and calculate
total electricity bill according to the given condition: dat
. If number of units are up to 100, the bill will be charged a’
the rate of Rs. 5 per unit ;
] Ifnumber of units are up to 200, the bill will be charged at
the rate of Rs. 10 per unit
. If number of units are above 200, the bill will be charged at
the rate of Rs. 20 per unit
#include
int mainQ {
int units;
double totalBill = 0;
// Taking input from the
std::cout << "Enter the number
er
's consumed: ";
std::cin >> units;
// Checking if the units are non-negative
if (units < 0) {
"Error: Please enter a non-negative number of units," <<
std::endl; _//
return 1; // Returning 1 to indicate an error
std::cerr <<
// Calculating the total electricity bill based on
if (units <= 100) {
totalBill = units * 5
} else if (units <= 200) {
totalBill = 100 *
the given conditions
5 + (units - 100) * 0;. }else {
AIBill = 100 * 5 + 100 * 10 + (units - 200) * 20;
}
tots
// Displaying the total electricity bill
stds: w
di:cout << "Total electricity bill: Rs. " << totalBill << std:endl;
return 0;
Program
Write a program to design an ATM interface to perform the
following transactions. You may initialize the balance with zero.
After each transaction, the program should ask the user to
perform another transaction. Based on the input (y/n) the
program either'redirects to the main interface or exit.
° Press B to check account Balance
+ Press D to cash Deposit
. Press W to cash Withdraw
#include
int main() {char choice;
double balance = 0.0;
do{
// Displaying the ATM menu
std::cout << "\nATM Interface\n";
std::cout << "Press B to check account Balance\n";
std::cout << "Press D to cash Deposit\n";
std::cout << "Press W to cash Withdraw\n";
std::cout << "Enter your choice: ";
std::cin >> choice;
// Handling user choice
switch (choice) {
case 'B':
case 'b':
// Displaying account balance
std::cout << "Your account balance is: Rs. " << balance <<
std::endl;
break;
ease 'd:
// Cash deposit
double depositamount;
std::cout << "Enter the deposit amount: Rs. ";
std::cin >> depositAmount;
// Validating deposit amount
if (depositamount > 0) {
balance += depositAmount;
std::cout << "Deposit successful. Your new balance is: Rs." <<
balance << std::endl;
}else {err << "Error: itt ‘1
< "Error: Please enter a positive deposit amount." <<
std::endl;
}
break;
case W:
// Cash withdrawal
double withdrawAmount;
std::cout << "Enter the withdrawal amount: Rs. ";
std::cin >> withdrawAmount;
// Validating withdrawal amount
if (withdrawAmount > 0 && withdrawAmount <= balance) {
balance -= withdrawAmount;
std::cout << "Withdrawal successful. Your new balance is: Rs."
«<< balance << std::endl;
err << "Error: Insufficient funds or invalid withdrawal
amount." << std::endl;
\
break;
default:
std::cert-<< "Error: Invalid choice. Please select a valid option.” <<
std::endl;
}
// Asking the user if they want to perform another transaction
out << "Do you want to perform another transaction? (y/n): "5
std::cin >> choice;
} while (choice == 'y' || choice == 'Y’);
std::cout << “Thank you for using the ATM. Goodbye! \n";return 0;
Jee eso ean (eaghly
Giissy ally release,
ai Te eso N oy edged a Ay API BKM C779)
10