You are on page 1of 17

Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Total Marks: 5

Obtained Marks:

Fundamentals of
Programming
Assignment # 02
Last date of Submission: 03 Jan 2022

Submitted To: Mr. Khwaja Bilal Hassan


_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Student Name: Haisam Abbas


______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Reg. Number: 21108105


______________________________________________________________________________________________________________________________________________________________________________________________________________________________________

1
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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;

cout<<"Please enter your total annual Income (in PKR) : "<<endl;


cin>>i;

if(i >= 50000 && i<100000)


{
cout<<"Your Income tax is : "<<i*5/100<<endl;

cout<<"Your Monthly Income Tax is : "<<i*5/100/12<<endl;


}

else if(i >= 100000 && i<300000)


{
cout<<"Your Income tax is : "<<i*6.5/100<<endl;

cout<<"Your Monthly Income Tax is : "<<i*6.5/100/12<<endl;


}

else if(i >= 300000 && i<500000)


{
cout<<"Your Income tax is : "<<i*7/100<<endl;

cout<<"Your Monthly Income Tax is : "<<i*7/100/12<<endl;


}

else
{
cout<<"Your Income Tax is : "<<i*10/100<<endl;

cout<<"Your Monthly Income Tax is : "<<i*10/100/12<<endl;

2
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

return 0;
}

Screenshots:

3
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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

COMPUTER SCIENCE DEPARTMENT

cout<<"''''''''''''''''Welcome to Learning Program for child''''''''''"<<endl;

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

COMPUTER SCIENCE DEPARTMENT

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

COMPUTER SCIENCE DEPARTMENT

Screenshots:

7
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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

COMPUTER SCIENCE DEPARTMENT

}
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

COMPUTER SCIENCE DEPARTMENT

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

COMPUTER SCIENCE DEPARTMENT

CONSOLE SCREEN:

11
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

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
{

cout <<"Please enter your completed courses: ";


cin>>a;
for(int i = 1; i<=a; i++)

12
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

{
cout <<"Enter the credit hours for course "<< i <<endl;
cin>>credit;

cout<<"Enter the Grade"<<endl;


cin>>grade;

if(grade == 'A')
{
cg = credit * A;
}

else if(grade == 'A-')


{
cg = credit * A_Minus;
}

else if(grade == 'B+')


{
cg = credit * B_Plus;
}

else if(grade == 'B' )


{
cg = credit * B;
}

else if(grade == 'B-')


{
cg = credit * B_Minus;
}

else if(grade == 'C+')


{
cg = credit * C_Plus;
}

else if(grade == 'C')

13
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

{
cg = credit * C;
}

else if(grade == 'C-')


{
cg = credit * C_Minus;
}

else if(grade == 'D+')


{
cg = credit * D_Plus;
}

else if(grade == 'D')


{
cg = credit * D;
}

else if(grade == 'D-')


{
cg = credit * D_Minus;
}

else if(grade == 'F')


{
cg = credit * F;
}

sum = sum + cg;


totalcredit = totalcredit + credit;

}
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

COMPUTER SCIENCE DEPARTMENT

GPA = sum/totalcredit;
cout<<"Your GPA is: "<<GPA<<endl;

return 0;
}

Screenshots:

15
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

16
Khwaja Bilal Hassan
Shaheed Zulfikar Ali Bhutto Institute of Science & Technology

COMPUTER SCIENCE DEPARTMENT

Console Screen:

<><><><<><><><><><><>THE END<><><><><><><><><><><

17
Khwaja Bilal Hassan

You might also like