0% found this document useful (0 votes)
15 views14 pages

Malyaka Rauf bsf23005119

The document contains 5 programming assignments submitted by Malyaka Rauf to Dr. Muhammad Anwar at the University of Education Lahore, Faisalabad Campus for the BS Computer Science program. The assignments include programs to find the maximum of 3 numbers, calculate a factorial, determine currency notes for a given amount, calculate an electricity bill based on units consumed, and design an ATM interface. Each assignment contains the code in C++ to solve the given problem and expected output.

Uploaded by

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

Malyaka Rauf bsf23005119

The document contains 5 programming assignments submitted by Malyaka Rauf to Dr. Muhammad Anwar at the University of Education Lahore, Faisalabad Campus for the BS Computer Science program. The assignments include programs to find the maximum of 3 numbers, calculate a factorial, determine currency notes for a given amount, calculate an electricity bill based on units consumed, and design an ATM interface. Each assignment contains the code in C++ to solve the given problem and expected output.

Uploaded by

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

University of Education Lahore

(Faisalabad Campus)

ASSIGNMENT
Programming Fundamental

Submitted by: Malyaka Rauf


Roll No: bsf23005119
Program: BS (Computer Science)
Submitted to: Dr. Muhammad Anwar
Program # 1:
Write a program to that can take three number as input
from the user and find the maximum number among
them.
#include<iostream>
using namespace std;
int main ()
{
int a, b, c, max;
cout<<”Enter three numbers:”;
cin>>a>>b>>c;
if(a>b&&b>c)
{
max=a;
}
else if(b>1&&b>c)
{
max=b;
}
else
{
max=c;
}
cout<<”The maximum number is:”<<max<<endl;
cout<<”Malyaka Rauf”;
return 0;
}

Output:

Program # 2:
Write a program which ask the user to enter a positive
integer and then calculate its factorial.
#include<iostream>
using namespace std;
int main ()
{
int num;
int factorial=1;
cout<<”Enter a positive integer”;
cin>>num;
if(num<0)
{
Cout<<”Enter positive integer.”<<endl;
}
for(int a=1;a<=num;a++)
{
factorial*=a;
}
cout<<”the factorial of”<<num<<”=”<<factorial<<endl;
cout<<”Malyaka Rauf”;
return 0;
}

Output:
Program # 3:
Write a program to count total number of currency
notes of 5000; 1000, 500, 100, 50, 20 and 10 in a given
amount.
#include<iostream>
using namespace std;
int main ()
{
int amount;
int n5000,n1000,n500,n100,n50,n20,n10;
n5000=n1000=n500=n100=n50=n20=n10=0;
cout<<”please enter your total Amount to find the notes:”;
cin>>amount;
switch(amount>=5000)
{
case 1:
n5000=amount/5000;
amount-=n5000*5000;
break;
}
Switch(amount>=1000)
{
case 1:
n1000=amount/1000;
amount-=n1000*1000;
break;
}
Switch(amount>=500)
{
case 1:
n500=amount/500;
amount-=n500*500;
break;
}
switch(amount>=100)
{
case 1:
n100=amount/100;
amount-=n100*100;
break;
}
switch(amount>=50)
{
case 1:
n50 =amount/50;
amount-=n50*50;
break;
}
switch(amount>=20)
{
case 1:
n20=amount/20;
amount-=n20*20;
break;
}
switch(amount>=10)
{
case 1:
n10=amount/10;
amount-=n10*10;
break;
}
cout<<”5000=”<<n5000<<endl;
cout<<”1000=”<<n1000<<endl;
cout<<”500=”<<n500<<endl;
cout<<”100=”<<n100<<endl;
cout<<”50=”<<n50<<endl;
cout<<”20=”<<n20<<endl;
cout<<”10=”<<n10<<endl;
cout<<”Malyaka Rauf;
return 0;
}

Output:

Program # 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.
#include<iostream>
using namespace std;
int main ()
{
int units;
int totalBill=0;
cout<<”Enter the number of units:”;
cin>>units;
if(units<=100)
{
totalBill=units*5;
}
else if(units<=200)
{
totalBill=100*5+(units-100)*10;
}
else
{
totalBill=100*5+100*10+(units-200)*20;
}
cout<<”Total electricity bill:Rs.”<<totalBill<<endl;
cout<<”Malyaka Rauf”;
return 0;
}

Output:
Program # 5:
Write a program to design ATM interface to perform the
following transection. You may initialize the balance
with zero. After each transection, the program should
ask the user to perform another transection. 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<iostream>
using namespace std;
int main ()
{
double balance =0.0;
char choice;
do {
cout<<”Welcome to the ATM interface!”<<endl;
cout<<”press B to check accountBalance”<<endl;
cout<<”press D to cash deposit “<<endl;
cout<<”press W to cash Withdraw”<<endl;
cout<<”press Q to quit”<<endl;
cin>>choice;
if(choice==’B’||choice’b’)
{
cout<<”your account balance is: $”<<balance<<endl;
}
else if(choice==’D’||choice==’d’)
{
Double depositAmount;
cout<<”Enter the deposit amount: $”;
cin>> depositAmount;
balance+=depositAmount;
cout<<”deposit successful. Your new balance is
$”<<balancs<<endl;
}
else if(choice==’W’||choice==’w’)
{
double withdrawAmount;
cout<<”Enter the withdrawAmount :$”;
cin>>withdrawAmount;
if(withdrawAmount>balance)
{
cout<<”insufficient funds. Your balance is $”<<balance<<endl;
}
Else
{
Balance-=withdrawAmount;
cout<<”withdraw successful. Your new balance is $”<<balance
<<endl;
}
}
else if(choice==’Q’||choice’q’)
{
cout<<”Thank you for using the ATM. Goodbye!”<<endl;
break;
}
else
{
cout<<”invalid choice. Please select a valid option.”<<endl;
}
char anotherTransection;
cout<<”Do you want to perform anotherTransection?(y/n):”;
cin>>anotherTransection;
if(anotherTransection !=’Y’&&anotherTransection!=’y’)
{
cout<<”Thank you for using the ATM. Goodbye!”<<endl;
break;
}
}
while(true)
cout<<”Malyaka Rauf”;
return 0;
}

Output:

You might also like