Professional Documents
Culture Documents
Assignment 2
Assignment 2
Total Marks: 5
Obtained Marks:
Fundamentals of
Programming
Assignment # 02
Last date of Submission: 03 Jan 2022
1
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
Question 1:
Code:
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */
int main() {
float i, incomeTax;
float tax;
else
{
cout<<"Your Income Tax is : "<<i*10/100<<endl;
2
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
return 0;
}
Screenshots:
3
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
CONSOLE SCREEN:
Question 2:
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input
loop */
int main() {
int num1, num2, r, correctAnswer, temp, n, total, ccounter, acounter;
char choice, Q;
srand(time(0));
int totalAttempts = 0;
4
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
ccounter=0;
acounter=0;
cout<<"Please enter your choice for learning practice: (1-2)"<<endl;
cout<<"Addition - 1"<<endl;
cout<<"Subtraction - 2"<<endl;
cin>>choice;
do
{
1 == '+';
2 == '-';
switch(choice)
{
case '1':
num1 = (rand() % 9) + 1;
num2 = (rand() % 9) + 1;
correctAnswer= num1 + num2;
cout<<num1<<"+"<<num2<<"="<<endl;
cin>>n;
cout<<num1<<"+"<<num2<<"="<<n<<endl;
if(n==num1+num2)
{
cout<<"The Answer is Correct"<<endl;
acounter++;
ccounter++;
}
else
{
cout<<"The Answer is not Correct"<<endl;
5
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
acounter++;
break;
}
case '2':
temp=num1;
num1=num2;
num2=temp;
num1 = (rand() % 9) + 1;
num2 = (rand() % 9) + 1;
correctAnswer = num1 - num2;
cout<<num1<<"-"<<num2<<"="<<endl;
cin>>n;
cout<<num1<<"-"<<num2<<"="<<n<<endl;
if(n==num1-num2)
{
cout<<"The Answer is Correct"<<endl;
acounter++;
ccounter++;
}
else
{
cout<<"The Answer is not Correct"<<endl;
ccounter++;
break;
}
}
cout<<"Do want to repeat it again? (Press 1 for Addition and 2 for
Subtraction)"<<endl;
cin>>choice;
}
while(choice != 'Q');
//Feedback
cout<<"Total Attempts:"<<acounter<<endl;
cout<<"Correct Attempts:"<<ccounter<<endl;
return 0;
}
6
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
Screenshots:
7
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
CONSOLE SCREEN:
Question 3:
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
cout<<" 1 2 3 4 5 6 7 8 9"<<endl;
int sum;
for(int i = 1; i<=1; i++)
{
cout<<"1";
for(int j = i; j<=9; j=j+i)
{
cout<<" "<<j;
8
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
}
for(int j = i; j<=9; j=j+i)
sum = sum + j;
cout<<" "<<sum;
cout<<endl;
}
//........................................................................
int a = 2;
for(int i = 1; i<=1; i++)
{
cout<<"2";
for(int j = i; j<=9; j=j+i)
{
cout<<" "<<j*2;
}
for(int j = i; j<=9; j=j+i)
sum = sum + j;
cout<<" "<<sum;
cout<<endl;
}
//........................................................................
int b = 3;
for(int i = 1; i<=1; i++)
{
cout<<"3";
for(int j = i; j<=9; j=j+i)
{
cout<<" "<<j*3;
}
for(int j = i; j<=9; j=j+i)
sum = sum + j;
cout<<" "<<sum;
cout<<endl;
}
//........................................................................
int c = 4;
for(int i = 1; i<=1; i++)
{
cout<<"4";
for(int j = i; j<=9; j=j+i)
{
cout<<" "<<j*4;
}
for(int j = i; j<=9; j=j+i)
9
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
sum = sum + j;
cout<<" "<<sum;
cout<<endl;
}
//........................................................................
int d = 5;
for(int i = 1; i<=1; i++)
{
cout<<"5";
for(int j = i; j<=9; j=j+i)
{
cout<<" "<<j*5;
}
for(int j = i; j<=9; j=j+i)
sum = sum + j;
cout<<" "<<sum;
cout<<endl;
}
return 0;
}
Screenshots:
10
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
CONSOLE SCREEN:
11
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
Question 4:
Code:
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
float A = 4.0;
float A_Minus = 3.7;
float B_Plus = 3.3;
float B = 3.0;
float B_Minus = 2.7;
float C_Plus = 2.3;
float C = 2.0;
float C_Minus = 1.7;
float D_Plus = 1.3;
float D = 1.0;
float D_Minus = 0.7;
float F = 0.0;
int a;
int c;
char grade;
float sum = 0;
float credit;
float cg = 0;
float totalcredit = 0;
float GPA = 0;
do
{
12
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
{
cout <<"Enter the credit hours for course "<< i <<endl;
cin>>credit;
if(grade == 'A')
{
cg = credit * A;
}
13
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
{
cg = credit * C;
}
}
cout<<"Terminate your Entry by Entring 0"<<endl;
cin>>credit;
}
while(credit != 0);
14
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
GPA = sum/totalcredit;
cout<<"Your GPA is: "<<GPA<<endl;
return 0;
}
Screenshots:
15
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
16
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology
Console Screen:
<><><><<><><><><><><>THE END<><><><><><><><><><><
17
Khwaja Bilal Hassan