Assignment 3 F22-8757 Noor-E-Adan

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 110

Assignment number 3

F22-8757_Noor-e-adan

Question number 1
Solution
----------------------- by while loop -----------------------------------

#include<iostream>

using namespace std;

int main()

int num1,num2,i=0,result;

char oper;
Assignment number 3
F22-8757_Noor-e-adan
while (oper!=’q’)

{cout<<"enter the first number"<<endl;

cin>>num1;

cout<<"enter the second number that you want"<<endl;

cin>>num2;

cout<<"enter the any operator that you want for result and for stop enter q"<<endl;

cin>>oper;

if(oper=='+')

result=num1+num2;

cout<<" the result is "<<ends<<result<<endl;

else if(oper=='-')

result = num1-num2;

cout<<"the result is"<<ends<<result<<endl;

else if(oper=='*')

result= num1*num2;

cout<<"the result is "<<result<<endl;

else if(oper=='/')

result=num1/num2;

cout<<"the result is "<<ends<<result<<endl;

else if(oper=='q')

break ;

}
Assignment number 3
F22-8757_Noor-e-adan
}

return 0;

------------------------------ by for loop --------------------------------

#include<iostream>

using namespace std;

int main()

int num1,num2,i,result;

char oper;

for (i=0;oper!=’q’;i++)

{cout<<"enter the first number"<<endl;

cin>>num1;

cout<<"enter the second number that you want"<<endl;

cin>>num2;

cout<<"enter the any operator that you want for result and for stop enter q"<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cin>>oper;

if(oper=='+')

result=num1+num2;

cout<<" the result is "<<ends<<result<<endl;

else if(oper=='-')

result = num1-num2;

cout<<"the result is"<<ends<<result<<endl;

else if(oper=='*')

result= num1*num2;

cout<<"the result is "<<result<<endl;

else if(oper=='/')

result=num1/num2;

cout<<"the result is "<<ends<<result<<endl;

else if(oper=='q')

break ;

return 0;

-------------------------------- by do while loop --------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int num1,num2,i,result;

char oper;

do

{cout<<"enter the first number"<<endl;

cin>>num1;

cout<<"enter the second number that you want"<<endl;

cin>>num2;

cout<<"enter the any operator that you want for result and for stop enter q"<<endl;

cin>>oper;

if(oper=='+')

{
Assignment number 3
F22-8757_Noor-e-adan
result=num1+num2;

cout<<" the result is "<<ends<<result<<endl;

else if(oper=='-')

result = num1-num2;

cout<<"the result is"<<ends<<result<<endl;

else if(oper=='*')

result= num1*num2;

cout<<"the result is "<<result<<endl;

else if(oper=='/')

result=num1/num2;

cout<<"the result is "<<ends<<result<<endl;

else if(oper=='q')

break ;

i++;

while(oper!='q');

return 0;

Question number 2
Solution
Assignment number 3
F22-8757_Noor-e-adan

----------------------- by while loop -----------------------------------

#include<iostream>

using namespace std;

int main()

{ int i=1,num,count=0,j,result,num1,k,counter=0,num2,result2;

cout<<"enter any number"<<endl;

cin>>num;

while( i <= num) {

j=2;

while(j<i)

if(i%j==0)

{ count++;

break;

j++;

if(num==9)

{result=i-2;

result2=i-result;

if(result2+result==num)

{
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;

}}

if(count==0&&i!=1)

if(num==5||num==7)

{result=i-2;

result2=i-result;

if(result2+result==num)

cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;}

num1=num-i;

if(num1+i==num)

if(num1%2!=0 &&num1%3!=0&&num1%5!=0&&num1%7!=0&&num1%9!=0)

cout<<"the sum of number is"<<ends<<i<<ends<<"and"<<ends<<num1<<endl;

count=0;

i++;
Assignment number 3
F22-8757_Noor-e-adan
}

return 0;

-------------------------- by for loop -------------------------------------------

#include<iostream>
using namespace std;
int main()
{ int i,num,count=0,j,result,num1,k,counter=0,num2,result2;
cout<<"enter any number"<<endl;
cin>>num;
for( i=1;i <= num;i++) {
for(j=2;j<i;j++)
{
if(i%j==0)
{ count++;
break;
}
j++;
Assignment number 3
F22-8757_Noor-e-adan

}
if(num==9)
{result=i-2;
result2=i-result;
if(result2+result==num)
{
cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;
}}
if(count==0&&i!=1)
{
if(num==5||num==7)
{result=i-2;
result2=i-result;
if(result2+result==num)
{
cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;}
}

num1=num-i;
if(num1+i==num)

{
if(num1%2!=0 &&num1%3!=0&&num1%5!=0&&num1%7!=0&&num1%9!=0)

{
cout<<"the sum of number is"<<ends<<i<<ends<<"and"<<ends<<num1<<endl;
Assignment number 3
F22-8757_Noor-e-adan

count=0;

return 0;
}

------------------------------- by do while loop ---------------------------------------

#include<iostream>

using namespace std;

int main()

{ int i=1,num,count=0,j,result,num1,k,counter=0,num2,result2;

cout<<"enter any number"<<endl;

cin>>num;

do {

do
Assignment number 3
F22-8757_Noor-e-adan
{ j=2;

if(i%j==0)

{ count++;

break;

j++;

}while(j<i);

if(num==9)

{result=i-2;

result2=i-result;

if(result2+result==num)

cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;

}}

if(count==0&&i!=1)

if(num==5||num==7)

{result=i-2;

result2=i-result;

if(result2+result==num)

cout<<"the sum is"<<ends<<result<<ends<<"and"<<ends<<result2<<endl;}

num1=num-i;

if(num1+i==num)

if(num1%2!=0 &&num1%3!=0&&num1%5!=0&&num1%7!=0&&num1%9!=0)
Assignment number 3
F22-8757_Noor-e-adan

cout<<"the sum of number is"<<ends<<i<<ends<<"and"<<ends<<num1<<endl;

count=0;

i++;

}while(i<=num);

return 0;

Question number 3

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan
Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cmath>

using namespace std;

int main()

{int i=1,num;

float x;

cout<<"------------first point----------------"<<endl;

cout<<endl;

cout<<"enter any number that you want"<<endl;

cin>>x;

while(x>=0)

cout<<x<<ends<<ends;

x=x-0.5;

cout<<endl;

cout<<"-------------second point-----------------"<<endl;

cout<<endl;

cout<<"the square root of the numbers are "<<endl;

while(i<=50)
Assignment number 3
F22-8757_Noor-e-adan
{ if(i%2!=0)

{cout<<sqrt(i)<<ends<<ends;

i++;

cout<<endl;

cout<<"-------------third point--------------------"<<endl;

cout<<endl;

cout<<"enter the number"<<endl;

cin>>num;

i=1;

while(i<=num)

{cout<<"hello world"<<endl;

i++;

cout<<endl;

cout<<"---------------forth point---------------------"<<endl;

cout<<endl;

int num2,num1,oper,result;

cout<<"Enter any numbers that you want "<<ends;

cin>>num2;

cout<<"enter the second number that you want"<<ends;

cin>>num1;

i=1;

while(i<=10000)

{ cout<<"enter the operation that you want "<<endl;

cout<<"press 1 for addition "<<endl;

cout<<"press 2 for subtraction "<<endl;

cout<<"press 3 for multiplication "<<endl;

cout<<"press 4 for division "<<endl;

cout<<"press 5 for modulus "<<endl;


Assignment number 3
F22-8757_Noor-e-adan
cout<<"press 6 for factorial "<<endl;

cout<<"press 7 for exists "<<endl;

cout<<endl;

cout<<endl;

cout<<"enter the number that you want"<<endl;

cin>>oper;

switch(oper)

{case 1:

result=num2+num1;

cout<<"the sum of number are "<<ends<<result<<endl;

break;

case 2:

result=num2-num1;

cout<<"the subtraction of number is"<<ends<<result<<endl;

break;

case 3:

result=num2*num1;

cout<<"the multiplication of number is"<<ends<<result<<endl;

break;

case 4:

result=num2/num1;

cout<<"the division of number is"<<ends<<result<<endl;

break;

case 5:

result=num2%num1;

cout<<"the modulus of number is"<<ends<<result<<endl;

break;

case 6:

int j;

j=1;

result=1;
Assignment number 3
F22-8757_Noor-e-adan
while(j<=num1)

{result=result*j;

j++;

cout<<"the factorial of number 2 is"<<ends<<result<<endl;

break;

case 7:

exit(0);

break;

default:

cout<<"enter the valid value"<<endl;

break;

return 0;

---------------------- by do while ------------------------------------


Assignment number 3
F22-8757_Noor-e-adan
Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cmath>

using namespace std;

int main()

{int i=1,num;

float x;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"------------first point----------------"<<endl;

cout<<endl;

cout<<"enter any number that you want"<<endl;

cin>>x;

do{

cout<<x<<ends<<ends;

x=x-0.5;

while(x>=0);

cout<<endl;

cout<<"-------------second point-----------------"<<endl;

cout<<endl;

cout<<"the square root of the numbers are "<<endl;

do { if(i%2!=0)

{cout<<sqrt(i)<<ends<<ends;

i++;

}while(i<=50);

cout<<endl;

cout<<"-------------third point--------------------"<<endl;

cout<<endl;

cout<<"enter the number"<<endl;

cin>>num;

i=1;

do

{cout<<"hello world"<<endl;

i++;

}while(i<=num);

cout<<endl;

cout<<"---------------forth point---------------------"<<endl;

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
int num2,num1,oper,result;

cout<<"Enter any numbers that you want "<<ends;

cin>>num2;

cout<<"enter the second number that you want"<<ends;

cin>>num1;

i=1;

do

{ cout<<"enter the operation that you want "<<endl;

cout<<"press 1 for addition "<<endl;

cout<<"press 2 for subtraction "<<endl;

cout<<"press 3 for multiplication "<<endl;

cout<<"press 4 for division "<<endl;

cout<<"press 5 for modulus "<<endl;

cout<<"press 6 for factorial "<<endl;

cout<<"press 7 for exists "<<endl;

cout<<endl;

cout<<endl;

cout<<"enter the number that you want"<<endl;

cin>>oper;

switch(oper)

{case 1:

result=num2+num1;

cout<<"the sum of number are "<<ends<<result<<endl;

break;

case 2:

result=num2-num1;

cout<<"the subtraction of number is"<<ends<<result<<endl;

break;

case 3:

result=num2*num1;

cout<<"the multiplication of number is"<<ends<<result<<endl;


Assignment number 3
F22-8757_Noor-e-adan
break;

case 4:

result=num2/num1;

cout<<"the division of number is"<<ends<<result<<endl;

break;

case 5:

result=num2%num1;

cout<<"the modulus of number is"<<ends<<result<<endl;

break;

case 6:

int j;

j=1;

result=1;

do

{result=result*j;

j++;

} while(j<=num1);

cout<<"the factorial of number 2 is"<<ends<<result<<endl;

break;

case 7:

exit(0);

break;

default:

cout<<"enter the valid value"<<endl;

break;

}while(i<=10000);

return 0;
Assignment number 3
F22-8757_Noor-e-adan
}

--------------------------- by for loop ---------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cmath>

using namespace std;

int main()

{int i,num;

float x;

cout<<"------------first point----------------"<<endl;

cout<<endl;

cout<<"enter any number that you want"<<endl;

cin>>x;

for(i=1;x>=0;i++)

cout<<x<<ends<<ends;

x=x-0.5;

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"-------------second point-----------------"<<endl;

cout<<endl;

cout<<"the square root of the numbers are "<<endl;

for(i=1;i<=50;i++)

{ if(i%2!=0)

{cout<<sqrt(i)<<ends<<ends;

cout<<endl;

cout<<"-------------third point--------------------"<<endl;

cout<<endl;

cout<<"enter the number"<<endl;

cin>>num;

for(i=1;i<=num;i++)

{cout<<"hello world"<<endl;

cout<<endl;

cout<<"---------------forth point---------------------"<<endl;

cout<<endl;

int num2,num1,oper,result;

cout<<"Enter any numbers that you want "<<ends;

cin>>num2;

cout<<"enter the second number that you want"<<ends;

cin>>num1;

for(i=1;i<=10000;i++)

{ cout<<"enter the operation that you want "<<endl;

cout<<"press 1 for addition "<<endl;

cout<<"press 2 for subtraction "<<endl;


Assignment number 3
F22-8757_Noor-e-adan
cout<<"press 3 for multiplication "<<endl;

cout<<"press 4 for division "<<endl;

cout<<"press 5 for modulus "<<endl;

cout<<"press 6 for factorial "<<endl;

cout<<"press 7 for exists "<<endl;

cout<<endl;

cout<<endl;

cout<<"enter the number that you want"<<endl;

cin>>oper;

switch(oper)

{case 1:

result=num2+num1;

cout<<"the sum of number are "<<ends<<result<<endl;

break;

case 2:

result=num2-num1;

cout<<"the subtraction of number is"<<ends<<result<<endl;

break;

case 3:

result=num2*num1;

cout<<"the multiplication of number is"<<ends<<result<<endl;

break;

case 4:

result=num2/num1;

cout<<"the division of number is"<<ends<<result<<endl;

break;

case 5:

result=num2%num1;

cout<<"the modulus of number is"<<ends<<result<<endl;

break;

case 6:
Assignment number 3
F22-8757_Noor-e-adan
int j;

result=1;

for(j=1;j<=num1;j++)

{result=result*j;

cout<<"the factorial of number 2 is"<<ends<<result<<endl;

break;

case 7:

exit(0);

break;

default:

cout<<"enter the valid value"<<endl;

break;

return 0;

Question number 4

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cmath>

using namespace std;

int main()

{ double result,sum=0;

int i=1,num;

cout<<"enter the number that you want"<<endl;

cin>>num;

while(i<=num)

result=1 / pow(i,i);

cout<<"1/"<<i<<"^"<<i<<ends<<"="<<ends<<result<<endl;

sum+=result;

i++;

cout<<"the sum of all the numbers is"<<ends<<sum<<endl;

return 0;

-------------------- by do while ----------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cmath>

using namespace std;

int main()

{ double result,sum=0;

int i=1,num;

cout<<"enter the number that you want"<<endl;

cin>>num;

do

result=1 / pow(i,i);

cout<<"1/"<<i<<"^"<<i<<ends<<"="<<ends<<result<<endl;

sum+=result;

i++;
Assignment number 3
F22-8757_Noor-e-adan
}while(i<=num);

cout<<"the sum of all the numbers is"<<ends<<sum<<endl;

return 0;

------------------------------- by for loop -----------------------------------------

#include<iostream>

#include<cmath>

using namespace std;

int main()

{ double result,sum=0;

int i,num;

cout<<"enter the number that you want"<<endl;

cin>>num;

for(i=1;i<=num;i++)

result=1 / pow(i,i);

cout<<"1/"<<i<<"^"<<i<<ends<<"="<<ends<<result<<endl;

sum+=result;
Assignment number 3
F22-8757_Noor-e-adan
i++;

cout<<"the sum of all the numbers is"<<ends<<sum<<endl;

return 0;

Question number 5

Solution

----------------------- by while loop -----------------------------------

#include<iostream>

using namespace std;

int main()

{ int num,k,result,num1,temp;

cout<<"enter the number that want"<<endl;

cin>>num;

cout<<"enter the value of last number "<<endl;

cin>>k;

result=num+k;

num1=num;

cout<<num1<<ends;
Assignment number 3
F22-8757_Noor-e-adan
temp=num;

while(num<=result)

{if(num<=temp+3)

if(num%2==0)

num1= num1/2;

cout<<num1<<ends;

else if(num%2!=0)

num1=3*num1+1;

cout<<num1<<ends;

}}

else if(num==temp+4)

num1=num1/2;

cout<<num1<<ends;}

else if(num==temp+5)

num1=3*num1+1;

cout<<num1<<ends;

else if(num>temp+5&&num<=result)

num1=num1/2;

cout<<num1<<ends;
Assignment number 3
F22-8757_Noor-e-adan
}

num++;

return 0;

}
Assignment number 3
F22-8757_Noor-e-adan

-------------------------------------- by do while ------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int num,k,result,num1,temp;

cout<<"enter the number that want"<<endl;

cin>>num;

cout<<"enter the value of last number "<<endl;

cin>>k;

result=num+k;

num1=num;

cout<<num1<<ends;

temp=num;

do {if(num<=temp+3)

if(num%2==0)

num1= num1/2;

cout<<num1<<ends;

else if(num%2!=0)
Assignment number 3
F22-8757_Noor-e-adan
{

num1=3*num1+1;

cout<<num1<<ends;

}}

else if(num==temp+4)

num1=num1/2;

cout<<num1<<ends;}

else if(num==temp+5)

num1=3*num1+1;

cout<<num1<<ends;

else if(num>temp+5&&num<=result)

num1=num1/2;

cout<<num1<<ends;

num++;

}while(num<=result);

return 0;

----------------------------------- by for loop --------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int num,k,result,num1,temp,i;

cout<<"enter the number that want"<<endl;

cin>>num;

cout<<"enter the value of last number "<<endl;

cin>>k;

result=num+k;

num1=num;

cout<<num1<<ends;

temp=num;

for(i=1;num<=result;i++) {if(num<=temp+3)

if(num%2==0)

num1= num1/2;

cout<<num1<<ends;

else if(num%2!=0)
Assignment number 3
F22-8757_Noor-e-adan
{

num1=3*num1+1;

cout<<num1<<ends;

}}

else if(num==temp+4)

num1=num1/2;

cout<<num1<<ends;}

else if(num==temp+5)

num1=3*num1+1;

cout<<num1<<ends;

else if(num>temp+5&&num<=result)

num1=num1/2;

cout<<num1<<ends;

num++;

return 0;

Question number 6

Solution
Assignment number 3
F22-8757_Noor-e-adan

----------------------- by while loop -----------------------------------

#include<iostream>
Assignment number 3
F22-8757_Noor-e-adan
using namespace std;

int main()

int num1,num2,sum=0,temp1,square,i=0;

char ch='A';

cout<<"------------first point--------------"<<endl;

cout<<endl;

cout<<"enter the first number and it should be smaller than last number"<<endl;

cin>>num1;

temp1=num1;

cout<<"enter the last number "<<endl;

cin>>num2;

cout<<endl;

cout<<"-----------second point------------"<<endl;

cout<<"the odd numbers are "<<endl;

while(num1<=num2)

if(num1%2!=0)

cout<<num1<<ends;

num1++;

cout<<endl;

cout<<endl;

cout<<"------------third point-----------"<<endl;

num1=temp1;

while(num1<=num2)

if(num1%2==0)

{
Assignment number 3
F22-8757_Noor-e-adan
sum=sum+num1;

num1++;

cout<<" the sum of all even number are "<<ends<<ends<<sum<<endl;

num1=temp1;

cout<<endl;

cout<<endl;

cout<<"--------------forth pont-------------"<<endl;

cout<<"square of num1 to 10"<<endl;

while(num1<=temp1+10)

cout<<" the square of number"<<ends;

cout<<num1<<ends<<ends;

square=num1*num1;

cout<<square<<endl;

num1++;

num1=temp1;

cout<<endl;

cout<<endl;

cout<<"--------------fifth point--------------"<<endl;

sum=0;

cout<<"the square of odd numbers are "<<endl;

while(num1<=num2)

if(num1%2!=0)

{square=num1*num1;

cout<<"the square of"<<ends<<num1<<"are"<<ends<<ends<<square<<endl;

sum=sum+square;

}
Assignment number 3
F22-8757_Noor-e-adan
num1++;

cout<<"sum of the square of odd is"<<ends<<sum<<endl;

cout<<endl;

cout<<"-------------sixth point-----------------"<<endl;

cout<<endl;

cout<<" the uppercase alphabet are "<<endl;

while(i<=25)

{ cout<<ch<<ends;

ch++;

i++;

return 0;

---------------------- by do while --------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int num1,num2,sum=0,temp1,square,i=0;
Assignment number 3
F22-8757_Noor-e-adan
char ch='A';

cout<<"------------first point--------------"<<endl;

cout<<endl;

cout<<"enter the first number and it should be smaller than last number"<<endl;

cin>>num1;

temp1=num1;

cout<<"enter the last number "<<endl;

cin>>num2;

cout<<endl;

cout<<"-----------second point------------"<<endl;

cout<<"the odd numbers are "<<endl;

do

if(num1%2!=0)

cout<<num1<<ends;

num1++;

} while(num1<=num2);

cout<<endl;

cout<<endl;

cout<<"------------third point-----------"<<endl;

num1=temp1;

do{

if(num1%2==0)

sum=sum+num1;

num1++;

}while(num1<=num2);
Assignment number 3
F22-8757_Noor-e-adan
cout<<" the sum of all even number are "<<ends<<ends<<sum<<endl;

num1=temp1;

cout<<endl;

cout<<endl;

cout<<"--------------forth pont-------------"<<endl;

cout<<"square of num1 to 10"<<endl;

do{

cout<<" the square of number"<<ends;

cout<<num1<<ends<<ends;

square=num1*num1;

cout<<square<<endl;

num1++;

}while(num1<=temp1+10);

num1=temp1;

cout<<endl;

cout<<endl;

cout<<"--------------fifth point--------------"<<endl;

sum=0;

cout<<"the square of odd numbers are "<<endl;

do {

if(num1%2!=0)

{square=num1*num1;

cout<<"the square of"<<ends<<num1<<"are"<<ends<<ends<<square<<endl;

sum=sum+square;

num1++;

}while(num1<=num2);
Assignment number 3
F22-8757_Noor-e-adan
cout<<"sum of the square of odd is"<<ends<<sum<<endl;

cout<<endl;

cout<<"-------------sixth point-----------------"<<endl;

cout<<endl;

cout<<" the uppercase alphabet are "<<endl;

do{ cout<<ch<<ends;

ch++;

i++;

}while(i<=25);

return 0;

------------------------- by for loop ---------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int num1,num2,sum=0,temp1,square,i=0;
Assignment number 3
F22-8757_Noor-e-adan
char ch='A';

cout<<"------------first point--------------"<<endl;

cout<<endl;

cout<<"enter the first number and it should be smaller than last number"<<endl;

cin>>num1;

temp1=num1;

cout<<"enter the last number "<<endl;

cin>>num2;

cout<<endl;

cout<<"-----------second point------------"<<endl;

cout<<"the odd numbers are "<<endl;

for(i=1;num1<=num2;i++)

if(num1%2!=0)

cout<<num1<<ends;

num1++;

cout<<endl;

cout<<endl;

cout<<"------------third point-----------"<<endl;

num1=temp1;

for(i=1;num1<=num2;i++){

if(num1%2==0)

sum=sum+num1;

num1++;

}
Assignment number 3
F22-8757_Noor-e-adan
cout<<" the sum of all even number are "<<ends<<ends<<sum<<endl;

num1=temp1;

cout<<endl;

cout<<endl;

cout<<"--------------forth pont-------------"<<endl;

cout<<"square of num1 to 10"<<endl;

for(i=1;num1<=temp1+10;i++){

cout<<" the square of number"<<ends;

cout<<num1<<ends<<ends;

square=num1*num1;

cout<<square<<endl;

num1++;

num1=temp1;

cout<<endl;

cout<<endl;

cout<<"--------------fifth point--------------"<<endl;

sum=0;

cout<<"the square of odd numbers are "<<endl;

for(i=1;num1<=num2;i++) {

if(num1%2!=0)

{square=num1*num1;

cout<<"the square of"<<ends<<num1<<"are"<<ends<<ends<<square<<endl;

sum=sum+square;

num1++;

}
Assignment number 3
F22-8757_Noor-e-adan
cout<<"sum of the square of odd is"<<ends<<sum<<endl;

cout<<endl;

cout<<"-------------sixth point-----------------"<<endl;

cout<<endl;

cout<<" the uppercase alphabet are "<<endl;

for(i=1;i<=25;i++){ cout<<ch<<ends;

ch++;

return 0;

Question number 7

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan
Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int
i=1,sum,cake,icecream,yougurt,milk,flour,rice,potato,salt,tea,item,num=0,num1=0,num2=0,num3=0,num4=0,num
5=0,num6=0,num7=0,num8=0;
Assignment number 3
F22-8757_Noor-e-adan
while(i<=9)

cout<<"enter the item that you want"<<endl;

cout<<"if you want cake press 1"<<endl;

cout<<"if you want ice-cream press 2"<<endl;

cout<<"if you want yougurt press 3"<<endl;

cout<<"if you want milk press 4"<<endl;

cout<<"if you want flour press 5"<<endl;

cout<<"if you want rice press 6"<<endl;

cout<<"if you want potato press 7"<<endl;

cout<<"if you want salt press 8"<<endl;

cout<<"if you want tea press 9"<<endl;

cout<<"press 10 for exit"<<endl;

cin>>item;

if(item==1)

{ cout<<"--the price of cake is 20$"<<endl;

cout<<endl;

cout<<"enter the number of cake that you want"<<endl;

cin>>cake;

num=cake*20;

cout<<"the total price of cake is "<<ends<<num<<endl;

cout<<endl;

if(item==2)

{ cout<<"--the price of icecream is 15$"<<endl;

cout<<endl;

cout<<"enter the number of icecream that you want"<<endl;

cin>>icecream;

num1=icecream*15;

cout<<"the total price of icecream is "<<ends<<num1<<endl;

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
}

if(item==3)

{ cout<<"--the price of yougurt is 25$"<<endl;

cout<<endl;

cout<<"enter the number of yougurt that you want"<<endl;

cin>>yougurt;

num2=yougurt*25;

cout<<"the total price of yougurt is "<<ends<<num2<<endl;

cout<<endl;}

if(item==4)

{ cout<<"--the price of milk is 20$"<<endl;

cout<<endl;

cout<<"enter the number of milk that you want"<<endl;

cin>>milk;

num3=milk*20;

cout<<"the total price of milk is "<<ends<<num3<<endl;

cout<<endl;}

if(item==5)

{ cout<<"--the price of flour is 30$"<<endl;

cout<<endl;

cout<<"enter the number of flour that you want"<<endl;

cin>>flour;

num4=flour*30;

cout<<"the total price of flour is "<<ends<<num4<<endl;

cout<<endl;}

if(item==6)

{ cout<<"--the price of rice is 10$"<<endl;

cout<<endl;

cout<<"enter the number of rice that you want"<<endl;

cin>>rice;

num5=rice*10;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the total price of rice is "<<ends<<num5<<endl;

cout<<endl;}

if(item==7)

{ cout<<"--the price of potato is 5$"<<endl;

cout<<endl;

cout<<"enter the number of potato that you want"<<endl;

cin>>potato;

num6=potato*5;

cout<<"the total price of potato is "<<ends<<num6<<endl;

cout<<endl;}

if(item==8)

{ cout<<"--the price of salt is 10$"<<endl;

cout<<endl;

cout<<"enter the number of salt that you want"<<endl;

cin>>salt;

num7=salt*5;

cout<<"the total price of salt is "<<ends<<num7<<endl;

cout<<endl;}

if(item==9)

{ cout<<"--the price of tea is 10$"<<endl;

cout<<endl;

cout<<"enter the number of tea that you want"<<endl;

cin>>tea;

num8=tea*5;

cout<<"the total price of tea is "<<ends<<num8<<endl;

cout<<endl;}

if(item==10)

{ break;

}
Assignment number 3
F22-8757_Noor-e-adan
i++;

sum=num+num1+num2+num3+num4+num5+num6+num7+num8;

cout<<"the total amount of items are"<<ends<<sum<<endl;

cout<<endl;

if(sum>200)

{ cout<<"free shipping and handling"<<endl;

cout<<endl;

else if(sum<200)

{ sum=sum*10;

cout<<"the total amount by adding shipping and handling amount are "<<ends<<sum<<endl;

cout<<endl;

cout<<"^^^^-----------thanks for shopping here-------------^^^^"<<endl;

return 0;

------------------------------- by do while ----------------------------------------


Assignment number 3
F22-8757_Noor-e-adan
Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int
i=1,sum,cake,icecream,yougurt,milk,flour,rice,potato,salt,tea,item,num=0,num1=0,num2=0,num3=0,num4=0,num
5=0,num6=0,num7=0,num8=0;

do

cout<<"enter the item that you want"<<endl;

cout<<"if you want cake press 1"<<endl;

cout<<"if you want ice-cream press 2"<<endl;

cout<<"if you want yougurt press 3"<<endl;

cout<<"if you want milk press 4"<<endl;


Assignment number 3
F22-8757_Noor-e-adan
cout<<"if you want flour press 5"<<endl;

cout<<"if you want rice press 6"<<endl;

cout<<"if you want potato press 7"<<endl;

cout<<"if you want salt press 8"<<endl;

cout<<"if you want tea press 9"<<endl;

cout<<"press 10 for exit"<<endl;

cin>>item;

if(item==1)

{ cout<<"--the price of cake is 20$"<<endl;

cout<<endl;

cout<<"enter the number of cake that you want"<<endl;

cin>>cake;

num=cake*20;

cout<<"the total price of cake is "<<ends<<num<<endl;

cout<<endl;

if(item==2)

{ cout<<"--the price of icecream is 15$"<<endl;

cout<<endl;

cout<<"enter the number of icecream that you want"<<endl;

cin>>icecream;

num1=icecream*15;

cout<<"the total price of icecream is "<<ends<<num1<<endl;

cout<<endl;

if(item==3)

{ cout<<"--the price of yougurt is 25$"<<endl;

cout<<endl;

cout<<"enter the number of yougurt that you want"<<endl;

cin>>yougurt;

num2=yougurt*25;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the total price of yougurt is "<<ends<<num2<<endl;

cout<<endl;}

if(item==4)

{ cout<<"--the price of milk is 20$"<<endl;

cout<<endl;

cout<<"enter the number of milk that you want"<<endl;

cin>>milk;

num3=milk*20;

cout<<"the total price of milk is "<<ends<<num3<<endl;

cout<<endl;}

if(item==5)

{ cout<<"--the price of flour is 30$"<<endl;

cout<<endl;

cout<<"enter the number of flour that you want"<<endl;

cin>>flour;

num4=flour*30;

cout<<"the total price of flour is "<<ends<<num4<<endl;

cout<<endl;}

if(item==6)

{ cout<<"--the price of rice is 10$"<<endl;

cout<<endl;

cout<<"enter the number of rice that you want"<<endl;

cin>>rice;

num5=rice*10;

cout<<"the total price of rice is "<<ends<<num5<<endl;

cout<<endl;}

if(item==7)

{ cout<<"--the price of potato is 5$"<<endl;

cout<<endl;

cout<<"enter the number of potato that you want"<<endl;

cin>>potato;
Assignment number 3
F22-8757_Noor-e-adan
num6=potato*5;

cout<<"the total price of potato is "<<ends<<num6<<endl;

cout<<endl;}

if(item==8)

{ cout<<"--the price of salt is 10$"<<endl;

cout<<endl;

cout<<"enter the number of salt that you want"<<endl;

cin>>salt;

num7=salt*5;

cout<<"the total price of salt is "<<ends<<num7<<endl;

cout<<endl;}

if(item==9)

{ cout<<"--the price of tea is 10$"<<endl;

cout<<endl;

cout<<"enter the number of tea that you want"<<endl;

cin>>tea;

num8=tea*5;

cout<<"the total price of tea is "<<ends<<num8<<endl;

cout<<endl;}

if(item==10)

{ break;

i++;

}while(i<=9);

sum=num+num1+num2+num3+num4+num5+num6+num7+num8;

cout<<"the total amount of items are"<<ends<<sum<<endl;

cout<<endl;

if(sum>200)

{ cout<<"free shipping and handling"<<endl;


Assignment number 3
F22-8757_Noor-e-adan
cout<<endl;

else if(sum<200)

{ sum=sum*10;

cout<<"the total amount by adding shipping and handling amount are "<<ends<<sum<<endl;

cout<<endl;

cout<<"^^^^-----------thanks for shopping here-------------^^^^"<<endl;

return 0;

------------------------------ by for loop -------------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()
Assignment number 3
F22-8757_Noor-e-adan
{ int
i,sum,cake,icecream,yougurt,milk,flour,rice,potato,salt,tea,item,num=0,num1=0,num2=0,num3=0,num4=0,num5=
0,num6=0,num7=0,num8=0;

for(i=1;i<=9;i++)

cout<<"enter the item that you want"<<endl;

cout<<"if you want cake press 1"<<endl;

cout<<"if you want ice-cream press 2"<<endl;

cout<<"if you want yougurt press 3"<<endl;

cout<<"if you want milk press 4"<<endl;

cout<<"if you want flour press 5"<<endl;

cout<<"if you want rice press 6"<<endl;

cout<<"if you want potato press 7"<<endl;

cout<<"if you want salt press 8"<<endl;

cout<<"if you want tea press 9"<<endl;

cout<<"press 10 for exit"<<endl;

cin>>item;

if(item==1)

{ cout<<"--the price of cake is 20$"<<endl;

cout<<endl;

cout<<"enter the number of cake that you want"<<endl;

cin>>cake;

num=cake*20;

cout<<"the total price of cake is "<<ends<<num<<endl;

cout<<endl;

if(item==2)

{ cout<<"--the price of icecream is 15$"<<endl;

cout<<endl;

cout<<"enter the number of icecream that you want"<<endl;

cin>>icecream;
Assignment number 3
F22-8757_Noor-e-adan
num1=icecream*15;

cout<<"the total price of icecream is "<<ends<<num1<<endl;

cout<<endl;

if(item==3)

{ cout<<"--the price of yougurt is 25$"<<endl;

cout<<endl;

cout<<"enter the number of yougurt that you want"<<endl;

cin>>yougurt;

num2=yougurt*25;

cout<<"the total price of yougurt is "<<ends<<num2<<endl;

cout<<endl;}

if(item==4)

{ cout<<"--the price of milk is 20$"<<endl;

cout<<endl;

cout<<"enter the number of milk that you want"<<endl;

cin>>milk;

num3=milk*20;

cout<<"the total price of milk is "<<ends<<num3<<endl;

cout<<endl;}

if(item==5)

{ cout<<"--the price of flour is 30$"<<endl;

cout<<endl;

cout<<"enter the number of flour that you want"<<endl;

cin>>flour;

num4=flour*30;

cout<<"the total price of flour is "<<ends<<num4<<endl;

cout<<endl;}

if(item==6)

{ cout<<"--the price of rice is 10$"<<endl;

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cout<<"enter the number of rice that you want"<<endl;

cin>>rice;

num5=rice*10;

cout<<"the total price of rice is "<<ends<<num5<<endl;

cout<<endl;}

if(item==7)

{ cout<<"--the price of potato is 5$"<<endl;

cout<<endl;

cout<<"enter the number of potato that you want"<<endl;

cin>>potato;

num6=potato*5;

cout<<"the total price of potato is "<<ends<<num6<<endl;

cout<<endl;}

if(item==8)

{ cout<<"--the price of salt is 10$"<<endl;

cout<<endl;

cout<<"enter the number of salt that you want"<<endl;

cin>>salt;

num7=salt*5;

cout<<"the total price of salt is "<<ends<<num7<<endl;

cout<<endl;}

if(item==9)

{ cout<<"--the price of tea is 10$"<<endl;

cout<<endl;

cout<<"enter the number of tea that you want"<<endl;

cin>>tea;

num8=tea*5;

cout<<"the total price of tea is "<<ends<<num8<<endl;

cout<<endl;}
Assignment number 3
F22-8757_Noor-e-adan
if(item==10)

{ break;

sum=num+num1+num2+num3+num4+num5+num6+num7+num8;

cout<<"the total amount of items are"<<ends<<sum<<endl;

cout<<endl;

if(sum>200)

{ cout<<"free shipping and handling"<<endl;

cout<<endl;

else if(sum<200)

{ sum=sum*10;

cout<<"the total amount by adding shipping and handling amount are "<<ends<<sum<<endl;

cout<<endl;

cout<<"^^^^-----------thanks for shopping here-------------^^^^"<<endl;

return 0;

Question number 8

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int i=1,subject,count=0,count1=0,count2=0,count3=0,count4=0,count5=0;

char grade;

cout<<"enter the number of subjects"<<endl;

cin>>subject;

while(i<=subject)

{cout<<"enter the grade"<<endl;

cin>>grade;

if(grade=='a'||grade=='A')

{ count++;

if(grade=='b'||grade=='B')

{ count1++;

if(grade=='c'||grade=='C')

{ count2++;
Assignment number 3
F22-8757_Noor-e-adan
}

if(grade=='d'||grade=='D')

{ count3++;

if(grade=='e'||grade=='E')

{ count4++;

if(grade=='f'||grade=='F')

{ count5++;

i++;

cout<<endl;

cout<<"A :"<<ends<<count<<endl;

cout<<"B :"<<ends<<count1<<endl;

cout<<"C :"<<ends<<count2<<endl;

cout<<"D :"<<ends<<count3<<endl;

cout<<"E :"<<ends<<count4<<endl;

cout<<"F :"<<ends<<count5<<endl;

return 0;

--------------------------------- by do while loop ---------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int i=1,subject,count=0,count1=0,count2=0,count3=0,count4=0,count5=0;

char grade;

cout<<"enter the number of subjects"<<endl;

cin>>subject;

do

{cout<<"enter the grade"<<endl;

cin>>grade;

if(grade=='a'||grade=='A')

{ count++;

if(grade=='b'||grade=='B')

{ count1++;

if(grade=='c'||grade=='C')

{ count2++;
Assignment number 3
F22-8757_Noor-e-adan
}

if(grade=='d'||grade=='D')

{ count3++;

if(grade=='e'||grade=='E')

{ count4++;

if(grade=='f'||grade=='F')

{ count5++;

i++;

}while(i<=subject);

cout<<endl;

cout<<"A :"<<ends<<count<<endl;

cout<<"B :"<<ends<<count1<<endl;

cout<<"C :"<<ends<<count2<<endl;

cout<<"D :"<<ends<<count3<<endl;

cout<<"E :"<<ends<<count4<<endl;

cout<<"F :"<<ends<<count5<<endl;

return 0;

------------------------------- by for loop ---------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{ int i,subject,count=0,count1=0,count2=0,count3=0,count4=0,count5=0;

char grade;

cout<<"enter the number of subjects"<<endl;

cin>>subject;

for(i=1;i<=subject;i++)

{cout<<"enter the grade"<<endl;

cin>>grade;

if(grade=='a'||grade=='A')

{ count++;

if(grade=='b'||grade=='B')

{ count1++;

if(grade=='c'||grade=='C')

{ count2++;
Assignment number 3
F22-8757_Noor-e-adan
}

if(grade=='d'||grade=='D')

{ count3++;

if(grade=='e'||grade=='E')

{ count4++;

if(grade=='f'||grade=='F')

{ count5++;

cout<<endl;

cout<<"A :"<<ends<<count<<endl;

cout<<"B :"<<ends<<count1<<endl;

cout<<"C :"<<ends<<count2<<endl;

cout<<"D :"<<ends<<count3<<endl;

cout<<"E :"<<ends<<count4<<endl;

cout<<"F :"<<ends<<count5<<endl;

return 0;

Question number 9

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int reminder,i=0,num;

cout<<"enter the number that you want "<<endl;

cin>>num;

cout<<"the binary number are "<<endl;

cout<<endl;

if(num==0||num==1)

{cout<<num;

else

while(num!=0)

reminder=num%2;

num/=2;

cout<<reminder;

}}

cout<< endl;

return 0;
Assignment number 3
F22-8757_Noor-e-adan
}

--------------------------------- by do while loop ----------------------------------------

#include<iostream>

using namespace std;

int main()

int reminder,i=0,num;

cout<<"enter the number that you want "<<endl;

cin>>num;

cout<<"the binary number are "<<endl;

cout<<endl;

if(num==0||num==1)

{cout<<num;

else

do

reminder=num%2;

num/=2;

cout<<reminder;

}while(num!=0);}

cout<< endl;
Assignment number 3
F22-8757_Noor-e-adan
return 0;

--------------------------------------- by for loop --------------------------------------

#include<iostream>

using namespace std;

int main()

int reminder,i,num;

cout<<"enter the number that you want "<<endl;

cin>>num;

cout<<"the binary number are "<<endl;

cout<<endl;

if(num==0||num==1)

{cout<<num;

else

for(i=0;num!=0;i++)

reminder=num%2;
Assignment number 3
F22-8757_Noor-e-adan
num/=2;

cout<<reminder;

}}

cout<< endl;

return 0;

Question number 10

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int i=1,j,k,size;

char ch;

cout<<"enter the size of pattern"<<endl;

cin>>size;

cout<<"enter the number for you choice pattern 1 to 4"<<endl;

cin>>ch;
Assignment number 3
F22-8757_Noor-e-adan
switch(ch)

case '1':

i=1;

while(i<=size)

{ j=1;

while(j<=size)

{cout<<i;

j++;

cout<<endl;

i++;}}

break;

case '2':

i=1;

while(i<=size)

{ j=1;

while(j<=size)

cout<<j;

j++;

}cout<<endl;

i++;

} break;

case '3':

i=size;

while(i>=1)

{ j=1;

while(j<=size)
Assignment number 3
F22-8757_Noor-e-adan
{

cout<<i;

j++;

}cout<<endl;

i--;;

break;

case '4':

i=1;

while(i<=size)

{ j=size;

while(j>=1)

cout<<j;

j--;

}cout<<endl;

i++;

} break;

default:

cout<<"enter the correct value"<<endl;

break;

cout<<endl;

return 0;

------------------------------------- by do while ------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int i=1,j,k,size;

char ch;

cout<<"enter the size of pattern"<<endl;

cin>>size;

cout<<"enter the number for you choice pattern 1 to 4"<<endl;

cin>>ch;

switch(ch)

case '1':

i=1;

do

{ j=1;

{cout<<i;

j++;

}while(j<=size);

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
i++;}while(i<=size);}

break;

case '2':

i=1;

do

{ j=1;

do

cout<<j;

j++;

} while(j<=size);

cout<<endl;

i++;

} while(i<=size);break;

case '3':

i=size;

do

{ j=1;

do

cout<<i;

j++;

}while(j<=size);cout<<endl;

i--;;

} while(i>=1);

break;

case '4':

i=1;

do

{ j=size;
Assignment number 3
F22-8757_Noor-e-adan
do

cout<<j;

j--;

}while(j>=1);cout<<endl;

i++;

} while(i<=size);break;

default:

cout<<"enter the correct value"<<endl;

break;

}while(i<=size);

cout<<endl;

return 0;

----------------------------------- by for loop ----------------------------------------------

#include<iostream>

using namespace std;

int main()
Assignment number 3
F22-8757_Noor-e-adan
{

int i=1,j,k,size;

char ch;

cout<<"enter the size of pattern"<<endl;

cin>>size;

cout<<"enter the number for you choice pattern 1 to 4"<<endl;

cin>>ch;

switch(ch)

case '1':

for(i=1;i<=size;i++)

for(j=1;j<=size;j++)

{cout<<i;

cout<<endl;

}}

break;

case '2':

for(i=1;i<=size;i++)

for(j=1;j<=size;j++)

cout<<j;
Assignment number 3
F22-8757_Noor-e-adan
}

cout<<endl;

} break;

case '3':

for(i=size;i>=1;i--)

for(j=1;j<=size;j++)

cout<<i;

}cout<<endl;

break;

case '4':

for(i=1;i<=size;i++)

for(j=size;j>=1;j--)

cout<<j;

}cout<<endl;

} break;

default:

cout<<"enter the correct value"<<endl;

break;
Assignment number 3
F22-8757_Noor-e-adan

cout<<endl;

return 0;

Question number 11

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

{int i=1,j,k,size;

cout<<"enter the size in odd number"<<endl;

cin>>size;

while(i<=size)

{k=size;

while(k>=i)

{cout<<" ";

k--;

j=2;

while(j<=2*i)

{cout<<"*";

j++;

cout<<endl;

i++;
Assignment number 3
F22-8757_Noor-e-adan
}

i=1;

while(i<=size)

{k=1;

while(k<=i+1)

{cout<<" ";

k++;

j=size*2;

while(j>=2*i+2)

{cout<<"*";

j--;

cout<<endl;

i++;

------------------------------- by do while loop ---------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>

using namespace std;

int main()

{int i=1,j,k,size;

cout<<"enter the size in odd number"<<endl;

cin>>size;

do

{k=size;

do

{cout<<" ";

k--;

}while(k>=i);

j=2;

do

{cout<<"*";

j++;

}while(j<=2*i);

cout<<endl;

i++;

}while(i<=size);

i=1;

do

{k=1;

do

{cout<<" ";

k++;

}while(k<=i+1);

j=size*2;

do

{cout<<"*";

j--;
Assignment number 3
F22-8757_Noor-e-adan
}while(j>=2*i+2);

cout<<endl;

i++;

}while(i<size);

--------------------------------- by for loop -----------------------------------------

#include<iostream>

using namespace std;

int main()

{int i,j,k,size;

cout<<"enter the size in odd number"<<endl;

cin>>size;

for(i=1;i<=size;i++)

{k=size;

for(k=size;k>=i;k--)

{cout<<" ";

for(j=2;j<=2*i;j++)
Assignment number 3
F22-8757_Noor-e-adan
{cout<<"*";

cout<<endl;

for(i=1;i<size;i++)

for(k=1;k<=i+1;k++)

{cout<<" ";

j=size*2;

for (j=size*2;j>=2*i+2;j--)

{cout<<"*";

cout<<endl;

Question number 12

Solution

----------------------- by while loop -----------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

using namespace std;

int main()

int n=0,count=0,draw=0;

char card;

bool check = false;

bool ace = true;

while (check == false)

cout << "enter the number of card " << ends;

cin >> card;

n++;

draw++;

if (card == 'A'||card=='a')

count = count + 10;

ace = true;

n = 0;

}
Assignment number 3
F22-8757_Noor-e-adan
else if (n == 1)

if (ace == true && card == 'J'||card =='j')

count = count + 10;

check = true;

else if (card == 'j' || card == 'k' || card == 'q' || card == 'Q' || card == 'J' || card == 'K')

count = count + 10;

else if (card >= '2' || card <= '10')

count = count + 5;

else

cout << "invaid value" << endl;

check == true;

cout<<"the total number of card draw are "<<ends<<draw<<endl;

cout<<endl;

cout << "the total score you get are: " << ends << count << endl;

return 0;

}
Assignment number 3
F22-8757_Noor-e-adan

---------------------------- by do while loop --------------------------------------

#include<iostream>

using namespace std;

int main()

int n=0,count=0,draw=0;

char card;

bool check = false;

bool ace = true;

do

cout << "enter the number of card " << ends;

cin >> card;

n++;

draw++;

if (card == 'A'||card=='a')

count = count + 10;

ace = true;
Assignment number 3
F22-8757_Noor-e-adan
n = 0;

else if (n == 1)

if (ace == true && card == 'J'||card =='j')

count = count + 10;

check = true;

else if (card == 'j' || card == 'k' || card == 'q' || card == 'Q' || card == 'J' || card == 'K')

count = count + 10;

else if (card >= '2' || card <= '10')

count = count + 5;

else

cout << "invaid value" << endl;

check == true;

} while (check == false);

cout<<"the total number of card draw are "<<ends<<draw<<endl;

cout<<endl;

cout << "the total score you get are: " << ends << count << endl;
Assignment number 3
F22-8757_Noor-e-adan
return 0;

-------------------------------------- by for loop ----------------------------------------

#include<iostream>

using namespace std;

int main()

int n=0,count=0,draw=0,i;

char card;

bool check = false;

bool ace = true;

for(i=0;check == false;i++)

cout << "enter the number of card " << ends;

cin >> card;

n++;

draw++;

if (card == 'A'||card=='a')

count = count + 10;


Assignment number 3
F22-8757_Noor-e-adan
ace = true;

n = 0;

else if (n == 1)

if (ace == true && card == 'J'||card =='j')

count = count + 10;

check = true;

else if (card == 'j' || card == 'k' || card == 'q' || card == 'Q' || card == 'J' || card == 'K')

count = count + 10;

else if (card >= '2' || card <= '10')

count = count + 5;

else

cout << "invaid value" << endl;

check == true;

cout<<"the total number of card draw are "<<ends<<draw<<endl;

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
cout << "the total score you get are: " << ends << count << endl;

return 0;

Question number 13

Solution
Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

int main()

int turn1,turn2,turn3,turn4,sum1,add1=0,sum2,add2=0,i=1,count1=0,count2=0;

bool check = false;

cout<<endl;

cout<<"------------------***** start the game *****------------------------"<<endl;

cout<<endl;

srand(time(0));
Assignment number 3
F22-8757_Noor-e-adan
while(i<=5)

while(check==false)

cout<<"the first players spin"<<endl;

turn1=10+(rand()%29);

cout<<"first player turn 1 score"<<ends<<turn1<<endl;

turn2=10+(rand()%29);

cout<<"first player turn 2 score"<<ends<<turn2<<endl;

cout<<endl;

sum1=turn1+turn2;

add1=add1+sum1;

cout<<"the second player spin"<<endl;

turn3=10+(rand()%29);

cout<<"second player turn 1 score"<<ends<<turn3<<endl;

turn4=10+(rand()%29);

cout<<"second player turn 2 score"<<ends<<turn4<<endl;

cout<<endl;

sum2=turn3+turn4;

add2=add2+sum2;

cout<<"first player sum in"<<i<<" spin = "<<ends<<sum1<<endl;

cout<<endl;

cout<<"second player sum in "<<i<<"spin = "<<ends<<sum2<<endl;

if(sum1>=50&&sum2!=50)

cout<<"-------------^-^first player win the jackpot and he is the winner^-


^------------"<<endl;

check = true;

else if(sum2>=50&&sum1!=50)
Assignment number 3
F22-8757_Noor-e-adan
{

cout<<"-------------^-^second player win the jackpot and he is the winner^-


^------------"<<endl;

check = true;

else if(sum2>=50&&sum1>=50&&sum1==sum2)

cout<<" --------------------^-^both the players win the jackpot^-


^----------------"<<endl;

else if(sum1>sum2)

{count1++;

else if(sum1<sum2)

{count2++;

} i++;

if(count1>count2)

{cout<<"--------^-^first player is the winner of the match^-^---------------"<<endl;

else if(count1<count2)

{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;

else if(count1==count2)

{if(add1>add2)

{cout<<"--------^-^first player is the winner of the match^-^---------------"<<endl;

else if(add1<add2)
Assignment number 3
F22-8757_Noor-e-adan
{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;

else if(add1==add2)

cout<<"-------------------^-^match is tie^-^----------------------------"<<endl;

cout<<endl;

cout<<"---------******^-^thanks for playing the match^-^*******--------------------*****--------"<<endl;

return 0;

-------------------------------by do while loop---------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan
#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

int main()

int turn1,turn2,turn3,turn4,sum1,add1=0,sum2,add2=0,i=1,count1=0,count2=0;

bool check = false;

cout<<endl;

cout<<"------------------***** start the game *****------------------------"<<endl;

cout<<endl;

srand(time(0));

do

do

cout<<"the first players spin"<<endl;

turn1=10+(rand()%29);

cout<<"first player turn 1 score"<<ends<<turn1<<endl;

turn2=10+(rand()%29);

cout<<"first player turn 2 score"<<ends<<turn2<<endl;

cout<<endl;

sum1=turn1+turn2;

add1=add1+sum1;

cout<<"the second player spin"<<endl;

turn3=10+(rand()%29);

cout<<"second player turn 1 score"<<ends<<turn3<<endl;

turn4=10+(rand()%29);

cout<<"second player turn 2 score"<<ends<<turn4<<endl;

cout<<endl;
Assignment number 3
F22-8757_Noor-e-adan
sum2=turn3+turn4;

add2=add2+sum2;

cout<<"first player sum in"<<i<<" spin = "<<ends<<sum1<<endl;

cout<<endl;

cout<<"second player sum in "<<i<<"spin = "<<ends<<sum2<<endl;

if(sum1>=50&&sum2!=50)

cout<<"-------------^-^first player win the jackpot and he is the winner^-


^------------"<<endl;

check=true;

else if(sum2>=50&&sum1!=50)

cout<<"-------------^-^second player win the jackpot and he is the winner^-


^------------"<<endl;

check=true;

else if(sum2>=50&&sum1>=50&&sum1==sum2)

cout<<" --------------------^-^both the players win the jackpot^-


^----------------"<<endl;

else if(sum1>sum2)

{count1++;

else if(sum1<sum2)

{count2++;

} while(check==false);

i++;
Assignment number 3
F22-8757_Noor-e-adan
}while(i<=5);

if(count1>count2)

{cout<<"--------^-^first player is the winner of the match^-^---------------"<<endl;

else if(count1<count2)

{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;

else if(count1==count2)

{if(add1>add2)

{cout<<"--------^-^first player is the winner of the match^-^---------------"<<endl;

else if(add1<add2)

{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;

else if(add1==add2)

cout<<"-------------------^-^match is tie^-^----------------------------"<<endl;

cout<<endl;

cout<<"---------******^-^thanks for playing the match^-^*******--------------------*****--------"<<endl;

return 0;

------------------------------by for loop -----------------------------------------------------


Assignment number 3
F22-8757_Noor-e-adan

#include<iostream>

#include<cstdlib>

#include<ctime>

using namespace std;

int main()

int turn1,turn2,turn3,turn4,sum1,add1=0,sum2,add2=0,i,count1=0,count2=0;

bool check = false;

cout<<endl;

cout<<"------------------***** start the game *****------------------------"<<endl;

cout<<endl;

srand(time(0));

for(i=1;i<=5;i++)

for(i=1;check==false;i++)

{
Assignment number 3
F22-8757_Noor-e-adan
cout<<"the first players spin"<<endl;

turn1=10+(rand()%29);

cout<<"first player turn 1 score"<<ends<<turn1<<endl;

turn2=10+(rand()%29);

cout<<"first player turn 2 score"<<ends<<turn2<<endl;

cout<<endl;

sum1=turn1+turn2;

add1=add1+sum1;

cout<<"the second player spin"<<endl;

turn3=10+(rand()%29);

cout<<"second player turn 1 score"<<ends<<turn3<<endl;

turn4=10+(rand()%29);

cout<<"second player turn 2 score"<<ends<<turn4<<endl;

cout<<endl;

sum2=turn3+turn4;

add2=add2+sum2;

cout<<"first player sum in"<<i<<" spin = "<<ends<<sum1<<endl;

cout<<endl;

cout<<"second player sum in "<<i<<"spin = "<<ends<<sum2<<endl;

if(sum1>=50&&sum2!=50)

cout<<"-------------^-^first player win the jackpot and he is the winner^-


^------------"<<endl;

check=true;

else if(sum2>=50&&sum1!=50)

cout<<"-------------^-^second player win the jackpot and he is the winner^-


^------------"<<endl;

check=true;

}
Assignment number 3
F22-8757_Noor-e-adan
else if(sum2>=50&&sum1>=50&&sum1==sum2)

cout<<" --------------------^-^both the players win the jackpot^-


^----------------"<<endl;

else if(sum1>sum2)

{count1++;

else if(sum1<sum2)

{count2++;

if(count1>count2)

{cout<<"--------^-^first player is the winner of the match^-^---------------"<<endl;

else if(count1<count2)

{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;

else if(count1==count2)

{if(add1>add2)

{cout<<"--------^-^first player is the winner of the match^-^---------------"<<endl;

else if(add1<add2)

{cout<<"--------^-^second player is the winner of the match^-^---------------"<<endl;

else if(add1==add2)

{
Assignment number 3
F22-8757_Noor-e-adan
cout<<"-------------------^-^match is tie^-^----------------------------"<<endl;

cout<<endl;

cout<<"---------******^-^thanks for playing the match^-^*******--------------------*****--------"<<endl;

return 0;

You might also like