1st CS Assignment
Submitted By:
Zameer Hussain
Submitted To:
Dr. Muhammad Anwar
Subject:
Programming Fundamental
Assignment
1. Write a program to that can take three numbers as input from the user and find the maximum
number among them.
2. Write a program which ask the user to enter a positive integer and then calculate its factorial.
3. Write a program to count total number of currency notes of 5000, 1000, 500, 100, 50, 20 and 10 in
a given amount.
4. Write a program to input electricity unit consumed and calculate total electricity bill according to
the given condition:
If number of units are up to 100, the bill will be charged at the rate of Rs. 5 per unit
If number 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
5. Write a program to design 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
Task 1
Program to find maximum number
#include <iostream>
using namespace std;
int main() {
int num1, num2, num3;
char another_num;
do {
cout << "Enter value of num1 number: ";
cin >> num1;
cout << "Enter value of num2 number: ";
cin >> num2;
cout << "Enter value of num3 number: ";
cin >> num3;
if (num1 >= num2 && num2 >= num3) {
cout << "Maximum number is " << num1;
}
else if (num2 >= num1 && num2 >= num3) {
cout << "Maximum number is " << num2;
}
else {
cout << "maximum number is: " <<num3;
}
cout << "\nDo you want to play again? (Enter 'y' or 'n'): ";
cin >> another_num;
} while (another_num == 'y' || another_num == 'Y');
cout << "Game exiting." << endl;
cout<<"Zameer Hussain"<<endl;
return 0;
} Output:
Task 2
Program to find the Factorial of positive integer
#include <iostream>
using namespace std;
int main ()
{
int num;
long factorial = 1;
cout<<"Enter number to find its factorial: ";
cin>>num;
if(num < 0)
{
cout<<"please enter poitivew integer.";
}
else{
for(int i = 1; i <= num; i++)
factorial *= i;
cout<<"Factorial of number " <<num <<" is "<<factorial <<endl;
}
}
Output:
Task 3
Program to calculate the Bill by Consumed units
#include <iostream>
using namespace std;
int main() {
int unit, bill;
cout<< "please enter consumed units: ";
cin>>unit;
if(unit <= 100){
bill = unit * 5;
}
else if(unit <= 200){
bill = unit * 10;
} cout<< "Your total bill is "<<bill << endl;
else {
bill = unit * 20;
}
}
Output:
Task 4
Program to count total numbers of currency notes
#include <iostream>
using namespace std;
int main() {
int amount, note5000 = 0, note1000 = 0, note500 = 0, note100 = 0, note50 = 0, note20 = 0, note10 = 0;
cout<<"Please Enter amout";
cin>>amount;
if(amount >= 5000){
note5000 = amount / 5000;
}
else if(amount>= 1000){
note1000 = amount /1000;
}
else if(amount>= 500){
note500 = amount /500;
}
else if(amount>= 100){
note100 = amount /100;
}
else if(amount>= 50){
note50 = amount /50;
}
else if(amount>= 20){
note20 = amount /20;
}
else if(amount>= 10){
note10 = amount /10;
}
cout<<"Number of 5000 notes is " <<note5000 <<endl;
cout<<"Number of 1000 note is" <<note1000<<endl;
cout<<"Number of500 notes is " <<note500 <<endl;
cout<<"Number of 100 notes is " <<note100 <<endl;
cout<<"Number of 50 notes is " <<note50<<endl;
cout<<"Number of 20 notes is " <<note20 <<endl;
cout<<"Number of 10 notes is " <<note10 <<endl;
}
Output:
Task 5
Program To perform Transections on ATM
#include <iostream>
using namespace std;
int main()
{
char choise;
do{
int balance = 0;
cout<<"ATM Interface"<<endl;
cout<<"Enter B to check account balance. "<<endl;
cout<<"Enter D to deposit cash. "<<endl;
cout<<"Enter W to withdraw cash. "<<endl;
cout<<"Enter E to Exit. "<<endl;
cin>>choise;
if(choise == 'B' || choise == 'b'){
cout<<"Your accont balance is RS. "<<balance;
}
else if(choise == 'D' || choise == 'd'){
int deposit_cash;
cout<<"Enter ammount to deposit: " <<endl;
cin>>deposit_cash;
balance = balance + deposit_cash;
cout<<"deposit of RS. "<<deposit_cash <<" successfull." <<endl;
}
else if(choise == 'w' || choise == 'W'){
int withdraw_amount;
cout<<"Enter amount to withdrawh: "<<endl;
cin>>withdraw_amount;
if(balance >= withdraw_amount ){
cout<<"Amount of "<<withdraw_amount <<"withdraw successfull."<<endl;
}
else{
cout<<"Oops! Insuficient Balance. "<<endl;
}
}
else if(choise == 'E' || choise == 'e'){
cout<<"Thank You ATM Interface is Exiting." <<endl;
break;
}
else{
cout<<"Invalid choice. Please select a correct choice" <<endl;
}
cout<<"You like to perform anorther transection say(y/n): ";
cin>>choise;
}
while(choise == 'y' || choise =='Y');
Output: