All Week Hard Coopy Word Program

You might also like

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

Title: Hotel

Management system

Submitted by:

Atta ul mohamin,
2020-cs-43

Submitted to:
:

Dr . Awais Hassan

For fulfillment of

Cs 142 programming fundamentals

Department of computer science

University of Engineering and Technology,Lahore


Programming fundamental

Week 1
(calculator to finding age)
#include<iostream>
using namespace std;
int main(){

cout<<"********************************"<<endl;
cout<< "calculate age"<<endl;
cout<<"********************************"<<endl;

cout<<endl;
int a,b,c,d;
cin>>a;
cin>>b;

c=a+10;
d=b+10;

cout<<c<<endl;
cout<<d<<endl;
}
(Kg to gram)

#include<iostream>
using namespace std;

int main(){
cout<<"****************************"<<endl;
cout<<"unit converter value"<<endl;
cout<<"****************************"<<endl;
cout<<endl;

cout<<"kg to gram converter"<<endl;


int value;
int newvalue;

cout<<"enter value in kg"<<endl;


cin>>value;
newvalue = value *1000;

cout<<"our converted gram value is "<<newvalue;

}
(Area of rectangle)
#include<iostream>
using namespace std;
int main(){

cout<<"********************************"<<endl;
cout<< "area of rectangle"<<endl;
cout<<"********************************"<<endl;

cout<<endl;
int a,b,c;

cin>>b;
cin>>c;

a=b*c;

cout<<"the area is"<<a<<endl;}


(Fabnoic series)
#include<iostream>
using namespace std;

int main(){
cout<<"****************************"<<endl;
cout<<"FIBONACI"<<endl;
cout<<"****************************"<<endl;

cout<<endl;
int m,l,c,d,e,f,g,h;
cin>>m;
cin>>l;

c=m+l;
d=l+c;
e=c+d;
f=d+e;
g=e+f;
h=f+g;
cout<<c<<endl;
cout<<d<<endl;
cout<<e<<endl;
cout<<f<<endl;
cout<<g<<endl;
cout<<h<<endl;
}
(Area diameter circumferance of CIRCLE)
#include<iostream>
using namespace std;
int main ()
{
cout<<"**************"<<endl;
cout<<"calculate area ,diameter,circumferance of circle"<<endl;
cout<<"***************"<<endl;

cout<<endl;

float d,r,c,a,pi=3.14285;

cout<<"enter the radius of circle"<<endl;


cin>> r;

d=2*r;
cout<<"diameter is"<<d<<endl;
cout<<endl;

a=pi*r*r;
cout<<"area i s: "<<a<<endl;

cout<<endl;
c=2*pi*r;
cout<<"\ncircumferance is"<<c<<endl;
}
( Aggregate of subjects)

#include<iostream>
using namespace std;
int main(){

cout<<"************************"<<endl;
cout<<"to find average marks of four subject"<<endl;
cout<<"*************************"<<endl;
cout<<endl;

float p,m,c,s;

cin>>p;
cin>>m;
cin>>c;
cin>>s;

float a;
a=(p+m+c+s)/4;

cout<<"aggrigate is: "<<a<<endl;}


(convert Celsius to faranhight)

#include<iostream>
using namespace std;
int main(){

cout<<"********************************"<<endl;
cout<< "celsius to faranhieght"<<endl;
cout<<"********************************"<<endl;

cout<<endl;
float f,c;
cin>>c;
f=c*1.8+32;
cout<<f<<endl;
}

(Finding merit of students)


#include<iostream>
using namespace std;

int main(){
cout<<"****************************"<<endl;
cout<<"merit calculator"<<endl;
cout<<"****************************"<<endl;
cout<<endl;
float a,b,c;
cout<<"ENTER MATRIC MARKS"<<endl;
cin>>a;
cout<<"ENTER FSC MARKS"<<endl;
cin>>b;
cout<<"ENTER ECAT MARKS"<<endl;
cin>>c;
float X;
X=a*0.25+b*.45+c*.30;
cout<<"AGGRIGRATE IS: "<<X<<endl;
}

Week 1 End
Week 2

(Input numbr is valid or not B/W40- 50 and 60 -70)


#include<iostream>
using namespace std;
int main(){

int x;
cout<<"put number."<<endl;
cin>>x;
if((x>40 && x<50)||(x>60 && x<70 )){
cout<<"the number is valid..";}

else
{
cout<<"invalid..";}
}

(Finding factorial)
#include<iostream>
using namespace std;
int main(){

int num;
cout<<"enter the number";
cin>>num;

for(int x=1 ; x<5 ; x=x+1){


num=num*x;
}
cout<<num;
}

(Finding multiple of given no )


using namespace std;
int main(){
cout<<"****************************"<<endl;
cout<<"ENTER THE 3 NUMBER"<<endl;
cout<<"****************************"<<endl;
cout<<"Enter 1st number"<<endl;
int n,a1,a2,a3,a4,a5;
cin>>n;

a1=n*1;
a2=n*2;
a3=n*3;
a4=n*4;
a5=n*5;
cout<<a1<<endl;
cout<<a2<<endl;
cout<<a3<<endl;
cout<<a4<<endl;
cout<<a5<<endl;

cout<<"enter second number"<<endl;


int m,b1,b2,b3,b4,b5;
cin>>m;

b1=m*1;
b2=m*2;
b3=m*3;
b4=m*4;
b5=m*5;
cout<<b1<<endl;
cout<<b2<<endl;
cout<<b3<<endl;
cout<<b4<<endl;
cout<<b5<<endl;
int x;
x=a1+a2+a3+a4+a5+b1+b2+b3+b4+b5;
cout<<"sum is: "<<x<<endl;
}

(input number is valid or not B\W 40 & 50)

#include<iostream>
using namespace std;
int main(){

int x;
cout<<"put number."<<endl;
cin>>x;

if((x>40 && x<50)){


cout<<"the number is valid..";}
else
{
cout<<"invalid..";}
}

(ZODIAC SIGN)
#include<iostream>
using namespace std;
int main(){

int x;
cout<<"date of birth..";
cin>>x;
int y;
cout<<"month of year..";
cin>>y;

if(((x>=22)||(x<=20))&&((y==1)||(y==12))){
cout<<"star is capricon..";}

else if(((x>=21)||(x<=19))&&((y==1)||(y==2))){
cout<<"star is aquarus..";}

else if(((x>=20)||(x<=20))&&((y==2)||(y==3))){
cout<<"star pisces.";}

else if(((x>=21)||(x<=19))&&((y==3)||(y==4))){
cout<<"star is aries..";}

else if(((x>=20)||(x<=20))&&((y==4)||(y==5))){
cout<<"star is taurus..";}

else if(((x>=21)||(x<=21))&&((y==5)||(y==6))){
cout<<"star is gimni..";}

else if(((x>=22)||(x<=23))&&((y==6)||(y==7))){
cout<<"star is cancers..";}

else if(((x>=24)||(x<=23))&&((y==7)||(y==8))){
cout<<"star is leo..";}

else if(((x>=24)||(x<=22))&&((y==8)||(y==9))){
cout<<"star is virgo..";}
else if(((x>=23)||(x<=22))&&((y==9)||(y==10))){
cout<<"star is libra..";}

else if(((x>=23)||(x<=22))&&((y==10)||(y==11))){
cout<<"star is scorpio..";}

else if(((x>=23)||(x<=20))&&((y==11)||(y==12))){
cout<<"star is segetarius..";}
return 0;

(Print only even number )


#include<iostream>
using namespace std;
int main(){

int n1;
cout<<"enter first numb..";
cin>>n1;
int n2;
cout<<"enter second number";
cin>>n2;

int sum=0;

for(int x=n1 ; x<=n2; x=x+1){


if(x % 2==0)
sum=sum+x;}
{cout<<"sum of even no"<<sum<<endl;}

(FABNOCI SERIES by loop)


#include<iostream>
using namespace std;
int main(){

int n1;
cout<<"enter first numb..";
cin>>n1;
int n2;
cout<<"enter second number";
cin>>n2;

int a;
cout<<"enter the fibnoic series..";
cin>>a;

int n3;

for(int x=1; x<=a ; x=x+1){

n3=n1+n2;
n1=n2;
n2=n3;
cout<<n3<<endl;
}}

(decimal to binary by input no B\W 1 to 15 )

#include<iostream>
using namespace std;
int main(){

int d;
cout<< "enter the decimal no";
cin>>d;
int a;

for(int x=1;x<=1 ;x=x+1){


a=d % 2;
d=d/2;}

int b;

for(int x=1;x<=1 ;x=x+1){


b=d % 2;
d=d/2;}

int c;

for(int x=1;x<=1 ;x=x+1){


c=d % 2;
d=d/2;}

int e;

for(int x=1;x<=1 ;x=x+1){


e=d % 2;
d=d/2;}
cout<<e<<c<<b<<a<<endl;
}

( Week 2 END)

(Week 3)
(Start)

(decimal to binary for any range)

#include<iostream>
using namespace std;
int main(){

int x,a;

cin>>a;
cout<<"enter the no"<<endl;
while(a!=0){

x=a%2;
cout<<x<<endl;
a=a/2;

}
}

(DISCOUNT ON PURCHASING)
#include<iostream>
using namespace std;
int main(){
cout<<"discount offer"<<endl;

cout<<endl;
int numbooks;
cout<<"enter quantity ofbook"<<endl;
cin>>numbooks;

int total;
total=numbooks*100;

float payable;

if(total >=10){

payable=total-(0.1*total);}
else{payable=total;}

cout<<"total payable amount for purchase.."<<payable;}

(print enen no B\W any two number)

#include<iostream>
using namespace std;
int main(){

int n1;
cout<<"enter first numb..";
cin>>n1;
int n2;
cout<<"enter second number";
cin>>n2;

int sum=0;

for(int x=n1 ; x<=n2; x=x+1){


if(x % 2==0)
sum=sum+x;}
{cout<<"sum of even no"<<sum<<endl;}

( Lilly)
#include<iostream>
using namespace std;
int main(){

int age;
int money=0;
int wash;
int toy;

cout<<"enter age";
cin>>age;
cout<<"price o washing machine";
cin>>wash;
cout<<"toy price";
cin>>toy;

for(int x=1;x<=age;x++){
if(x%2==0){money=money+(x/2*10)-1;}
else{money=money+toy;}
}
if(money>=wash){cout<<"can buy"<<money<<endl;}
else{cout<<"cannot buy"<<money<<endl;}
return 0;
}

(Back to the past)


#include<iostream>
using namespace std;
int main(){
int age=18;
int money,year;
cout<<"enter money";
cin>> money;

cout<<"enter year";
cin>> year;

int x,y;

for(x=1800;x<=year;x++)
{
y=x%2;if(y==0){money=money-12000;}
else{money=money-(12000+age*50);}
age=age+1;}

if(money>0){cout<<"money is greater"<<money<<endl;}
if(money<0){cout<<"money is lesser"<<money<<endl;}

return 0;
}

(MUSUM DISCOUNT )
#include <iostream>
using namespace std;
int main(){

int x;
cout<<"day is";

cin>>x;
int y;
cout<<"age of human";
cin>>y;

if(x==1 && y>=1){


cout<<"the musum is closed..";}

else if((x==2 || x==4) && (y>=1 && y<=100)){


cout<<" get half discount ..";}

else if((y>=13 && y<=20) && (x==3)){


cout<<"will get discount on wednesday";}
else if((y<=6 || y>=65) && (x>=1 && x<=7)) {
cout<<"your admission is free";}
else if((y>=6 && y<=12)&&(x==6 || x==7))
{cout<<"get discount on weekend";}
return 0;
}

(Simple table programm)

#include<iostream>
using namespace std;
int main(){

int num;
cout<<"enter the number";
cin>>num;

for(int x=1 ; x<=10 ; x=x+1){

cout<<num<<"*"<<x<<"="<<num*x<<endl;

}
}

(SECRET AGENT PEOGRAMM )

#include<stdlib.h>
#include<string.h>
#include<conio.h>
using namespace std;
int main(){

cout<<"*********************************************"<<endl;
cout<<"security management system"<<endl;
cout<<"*********************************************"<<endl;

string n1,n2,n3,n4;
string p1,p2,p3,p4;
string m1,m2,m3,m4;
string message1,message2,message3;
string sendto1,sendto2,sendto3;
string sender1,sender2,sender3;
int totalmessages=0;
string admin="ali";
string pas="12345";
int option=1;
int total=0;
string loginuser;

while(true){
system ("CLS");
cout<<"enter admin name"<<endl;
cin>>n1;
cout<<"enter pas code"<<endl;
cin>>p1;

if(admin==n1 && pas==p1){


cout<<"acees to system"<<endl;

while(option !=4){
system ("CLS");
cout<<"1. add new man record "<<endl;
cout<<"2. view all record "<<endl;
cout<<"3. change"<<endl;
cout<<"4. logout" <<endl;
getch();

cout<<"enter your option"<<endl;


cin>>option;
if(option==1){if(total==0){
cout<<"name"<<endl;
cin>>n2;
cout<<"pasword"<<endl;
cin>>p2;
total=total+1;
getch();
}
else if(total==1){
cout<<"name"<<endl;
cin>>n3;
cout<<"pasword"<<endl;
cin>>p3;
total=total+1;
getch();}
else if(total==2){cout<<"name"<<endl;
cin>>n4;
cout<<"pasword"<<endl;
cin>>p4;
total=total+1;
getch();}
}

if(option==2){cout<<"NAME\t"<<"PASWORD\t"<<endl;
cout<<n2<<"\t"<<p2<<"\t"<<endl;
cout<<n3<<"\t"<<p3<<"\t"<<endl;
cout<<n4<<"\t"<<p4<<"\t"<<endl;
getch();}

if(option==3){
string changename;

cout<<"enter the name of user change"<<endl;


cin>>changename;

if(changename==n2){
string newpin;
cout<<"enter new pin"<<endl;
cin>>newpin;
p2=newpin;
cout<<"your pin has sucesfuly changed"<<endl;
}
else if(changename==n3){
string newpin;
cout<<"enter new pin"<<endl;
cin>>newpin;
p3=newpin;
cout<<"your pin has sucesfuly changed"<<endl;
}

else if(changename==n4){
string newpin;
cout<<"enter new pin"<<endl;
cin>>newpin;
p4=newpin;
cout<<"your pin has sucesfuly changed"<<endl;}
getch();
}

if(option==4){

}}
else{
//code for other users..
bool isvaliduser=false;

if((n1==n2 && p1==p2))


{loginuser=n2;
isvaliduser=true;}

if((n1==n3 && p1==p3))


{loginuser=n3;
isvaliduser=true;}

if((n1==n4 && p1==p4))


{loginuser=n4;
isvaliduser=true;}

if (isvaliduser==false){
cout<<"invalid user"<<endl;}

if(isvaliduser){
system ("CLS");
int useroption=100;
while(useroption!=3){
cout<<"1. send msg"<<endl;
cout<<"2. view msg "<<endl;
cout<<"3. logout "<<endl;
cout<<"enter option"<<endl;
cin>>useroption;
if(useroption==1){
//send message code here
string receivername,sendmessage;

cout<<"enter user name whom we want to send"<<endl;


cin>>receivername;
cout<<"enter your message"<<endl;
cin>>sendmessage;
totalmessages=totalmessages+1;

if(totalmessages==1){
message1=sendmessage;
sendto1=receivername;
sender1=loginuser;}

if(totalmessages==2){
message2=sendmessage;
sendto2=receivername;
sender2=loginuser;}
if(totalmessages==3){
message3=sendmessage;
sendto3=receivername;
sender3=loginuser;}

if(totalmessages==3)
{totalmessages=0;}

}
if(useroption==2){
//show messages.
cout<<"Login User..."<<loginuser;
if(loginuser==sendto1){
cout<<sender1<<"send the message"<<endl;
cout<<message1;
cout<<endl;}
if(loginuser==sendto2){
cout<<sender2<<"send the message"<<endl;
cout<<message2;
cout<<endl;}
if(loginuser==sendto3){
cout<<sender3<<"send the message"<<endl;
cout<<message3;
cout<<endl;
}
cout<<"press any word to contiue"<<endl;
getch();
}

if(useroption==3){
cout<<"lodout"<<endl;}

}
}}}}

(UMS PROGRAMM WITHOUT ARRAY )


#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
using namespace std;
int main(){

cout<<"*********************************************"<<endl;
cout<<"university admission management system"<<endl;
cout<<"*********************************************"<<endl;

string name1,name2,name3;
float matric1,fsc1,ecat1=0,matric2=0,matric3,fsc2,fsc3,ecat2=0,ecat3;
float x,y,z;
int option;
int total=0;
while(option !=4){
system("CLS");
cout<<"1. add new student record "<<endl;
cout<<"2. view all record "<<endl;
cout<<"3. print the record in accending order"<<endl;
cout<<"4. exist"<<endl;
cout<<"enter option ";

cin>>option;
cout<<option;
if(option==1){if(total==0){
cout<<"name"<<endl;
cin>>name1;
cout<<"mtric"<<endl;
cin>>matric1;
cout<<"fsc"<<endl;
cin>>fsc1;
cout<<"entry"<<endl;
cin>>ecat1;
x=((matric1/1100)*0.25)+((fsc1/1100)*0.45)+((ecat1/400)*0.30);
x=x*100;
cout<<"percent1 "<<x<<endl;
total=total+1;

getch();
}
else if(total==1){
cout<<"name"<<endl;
cin>>name2;
cout<<"mtric"<<endl;
cin>>matric2;
cout<<"fsc"<<endl;
cin>>fsc2;
cout<<"entry"<<endl;
cin>>ecat2;
y=((matric2/1100)*0.25)+((fsc2/1100)*0.45)+((ecat2/400)*0.30);
y=y*100;
cout<<"percent2 "<<y<<endl;
total=total+1;
getch();
}
else if(total==2){
cout<<"name"<<endl;
cin>>name3;
cout<<"mtric"<<endl;
cin>>matric3;
cout<<"fsc"<<endl;
cin>>fsc3;
cout<<"entry"<<endl;
cin>>ecat3;
z=((matric3/1100)*0.25)+((fsc3/1100)*0.45)+((ecat3/400)*0.30);
z=z*100;
cout<<"percent3 "<<z<<endl;
total=total+1;

getch();
}
if(total>=3)
{total=1;}
}
cout<<option;

if(option==2){cout<<"NAME \t"<<"MATRIC \t"<<"FSC\t"<<"ECAT \t"<<"AGGRIGATE \t"<<endl;


cout<<name1<<"\t"<<matric1<<"\t"<<fsc1<<"\t"<<ecat1<<"\t"<<x<<"\t"<<endl;
cout<<name2<<"\t"<<matric2<<"\t"<<fsc2<<"\t"<<ecat2<<"\t"<<y<<"\t"<<endl;
cout<<name3<<"\t"<<matric3<<"\t"<<fsc3<<"\t"<<ecat3<<"\t"<<z<<"\t"<<endl;
getch();
}
if(option==3){
if(x>y && x>z){cout<<name1<<"\t"<<matric1<<"\t"<<fsc1<<"\t"<<ecat1<<"\t"<<x<<"\t"<<endl;

if(y>z){cout<<name2<<"\t"<<matric2<<"\t"<<fsc2<<"\t"<<ecat2<<"\t"<<y<<"\t"<<endl;
cout<<name3<<"\t"<<matric3<<"\t"<<fsc3<<"\t"<<ecat3<<"\t"<<z<<"\t"<<endl;}
if(z>y){ cout<<name3<<"\t"<<matric3<<"\t"<<fsc3<<"\t"<<ecat3<<"\t"<<z<<"\t"<<endl;
cout<<name2<<"\t"<<matric2<<"\t"<<fsc2<<"\t"<<ecat2<<"\t"<<y<<"\t"<<endl;}}

if(y>x && y>z){ cout<<name2<<"\t"<<matric2<<"\t"<<fsc2<<"\t"<<ecat2<<"\t"<<y<<"\t"<<endl;


if(x>z){ cout<<name1<<"\t"<<matric1<<"\t"<<fsc1<<"\t"<<ecat1<<"\t"<<x<<"\t"<<endl;
cout<<name3<<"\t"<<matric3<<"\t"<<fsc3<<"\t"<<ecat3<<"\t"<<z<<"\t"<<endl;}
if(z>x){cout<<name3<<"\t"<<matric3<<"\t"<<fsc3<<"\t"<<ecat3<<"\t"<<z<<"\t"<<endl;
cout<<name1<<"\t"<<matric1<<"\t"<<fsc1<<"\t"<<ecat1<<"\t"<<x<<"\t"<<endl;}}

if(z>x && z>y){ cout<<name3<<"\t"<<matric3<<"\t"<<fsc3<<"\t"<<ecat3<<"\t"<<z<<"\t"<<endl;


if(x>y){cout<<name1<<"\t"<<matric1<<"\t"<<fsc1<<"\t"<<ecat1<<"\t"<<x<<"\t"<<endl;
cout<<name2<<"\t"<<matric2<<"\t"<<fsc2<<"\t"<<ecat2<<"\t"<<y<<"\t"<<endl;}
if(y>x){ cout<<name2<<"\t"<<matric2<<"\t"<<fsc2<<"\t"<<ecat2<<"\t"<<y<<"\t"<<endl;
cout<<name1<<"\t"<<matric1<<"\t"<<fsc1<<"\t"<<ecat1<<"\t"<<x<<"\t"<<endl;}}

getch();
}
}
}
( Week 3 end)
Start
(Week 4 )

(print even number B\W any two no )

#include<iostream>
using namespace std;
int main(){

int n1;
cout<<"enter first numb..";
cin>>n1;
int n2;
cout<<"enter second number";
cin>>n2;

int sum=0;

for(int x=n1 ; x<=n2; x=x+1){


if(x % 2==0)
sum=sum+x;}
{cout<<"sum of even no"<<sum<<endl;}

(print even no else not)


#include<iostream>
#include<conio.h>
using namespace std;
int main(){

cout<<"*********************************************"<<endl;
cout<<"even no"<<endl;
cout<<"*********************************************"<<endl;
int x,y;

while(true){
cout<<"enter decimal no"<<endl;
cin>>x;

y=x%2;

if(y==0){
cout<<"the no is even"<<y<<endl;}

else {cout<<"not print"<<endl;}


}}

(SUM THE no AND THEIR MULTIPLE BY LOOP)

#include<iostream>
using namespace std;
int main(){
int n1,n2;
cout<<"enter first no";
cin>>n1;
cout<<"enter second no";
cin>>n2;
int a;
cout<<"enter multiple of no";
cin>>a;

for(int x=1 ; x<=a; x=x+1){cout<<x*n1<<endl;


}
for(int x=1;x<=a;x=x+1){cout<<x*n2<<endl;}

(SECRET AGENT BY ARRAY)


#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

using namespace std;


int main(){

cout<<"*********************************************"<<endl;
cout<<"security management system by ray"<<endl;
cout<<"*********************************************"<<endl;

string admin="ali";
string admpin="12345";
string usernam,userpin;
int admoption=0;

int totaluser=0;
string messages[100];
int totalmessages=0;
string sender[10];
string receiver[10];
int idx=0;
string name[10];
string pin[10];
int useroption=0;
while(true){
system("CLS");

cout<<"enter user name"<<endl;


cin>>usernam;
cout<<"enter pas code"<<endl;
cin>>userpin;

if(admin==usernam && admpin==userpin){


cout<<"acees to system"<<endl;
//he/is admin..

while(admoption !=4){
system ("CLS");
cout<<"1. add new man record "<<endl;
cout<<"2. view all record "<<endl;
cout<<"3. change"<<endl;
cout<<"4. log out" <<endl;
getch();

cout<<"enter your option"<<endl;


cin>>admoption;
if(admoption==1){
cout<<"name"<<endl;
cin>>name[totaluser];
cout<<"pasword"<<endl;
cin>>pin[totaluser];
totaluser=totaluser+1;
getch();
}
if(admoption==2){cout<<"NAME\t"<<"PASWORD\t"<<endl;
for(int idx=0;idx<totaluser;idx++){
cout<<name[idx]<<"\t";
cout<<pin[idx]<<"\t";}
cout<<"press any word to continue"<<endl;
getch();}
if(admoption==3){
string x;
string newpin;
cout<<"enter user name to change pin"<<endl;
cin>>x;
for(int idx=0;idx<totaluser;idx++){
if(name[idx]==x){cout<<"enter new pin" <<endl;
cin>>newpin;
pin[idx]=newpin;
}
cout<<"enter ny key to continue"<<endl;
getch();}}

}
}
else{ //other user code herre/..
string loginuser;
bool isuserfound=false;
for(int idx=0;idx<totaluser;idx++){
if(name[idx]==usernam && pin[idx]==userpin){
loginuser=usernam;
isuserfound=true;}}
if(isuserfound){

while(useroption!=3){
system("CLS");

cout<<"1. send msg"<<endl;


cout<<"2. view msg "<<endl;
cout<<"3. logout "<<endl;

cout<<"enter option"<<endl;
cin>>useroption;

if(useroption==1){
string message;
string greceiver;
cout<<"write ur messages here"<<endl;
cin>>message;
cout<<"enter name of reciever"<<endl;
cin>>greceiver;
messages[totalmessages]=message;
receiver[totalmessages]=greceiver;
sender[totalmessages]=loginuser;
totalmessages=totalmessages+1;
}

if(useroption==2){
for(int idx=0;idx<totalmessages;idx++){
if(receiver[idx]==loginuser){
cout<<sender[idx];
cout<<"send u the message"<<endl;
cout<<messages[idx];

}}
getch();}

}}

}}}
(week 5)

(largest dublicate by array)


#include<iostream>
using namespace std;
const int arraylenth=14;
int n;
int largestdublicate(int number[arraylenth]);
int main(){
int testarray[arraylenth]={1,2,2,2,2,0,2,0,2,3,8,9,2,3};
int lf=largestdublicate(testarray);
cout<<"largestdublicate no"<<lf<<endl;
}
int frequancy(int number[arraylenth],int n){

int f=0;
for(int i=0; i<number[arraylenth] ;i++){
int n=number[i];
if(number[i]==n){
f=f+1;

}
return f;
}
int largestdublicate(int number[arraylenth]){
int lf=-1;
int y;

for(int idx=0;idx<14;idx++){

y=frequancy(number, idx);
if(y>lf){
lf=y;
}

}
return lf;

(MONOTONIC)
#include<iostream>
using namespace std;
const int arraylenth=4;
bool ismonotonic(int numbers[arraylenth]);
bool isincreasing(int numbers[arraylenth]);
bool isdecreasing(int numbers[arraylenth]);
int main(){
int testarray[arraylenth]={1,2,7,5};
bool isarraymonotonic=ismonotonic(testarray);
if(isarraymonotonic==false){ cout<<"false";}
else{
cout<<"true";}
}

bool ismonotonic(int numbers[arraylenth]){


if(isincreasing(numbers)==true || isdecreasing(numbers)==true){
return true;

}else{
return false;
}

}
bool isincreasing(int numbers[arraylenth]){
for(int x=1;x<arraylenth;x++){
if (numbers[x-1]<numbers[x]){

}else{
return false;
}
}return true;
}
bool isdecreasing(int numbers[arraylenth]){
for(int x=1;x<arraylenth;x++){
if (numbers[x-1]>numbers[x]){

}else{
return false;
}
}return true;
}

(ROTATE ORDER)
#include<iostream>
using namespace std;
const int arraylenth=7;

void rightrotate(int numbers[arraylenth],int rotation);


int main(){
int testarray[arraylenth]={1,2,3,4,5,6,7};
rightrotate(testarray,2);
for(int idx=0;idx<arraylenth;idx++){
cout<<testarray[idx]<<" ,";

}
}
void rightrotate(int numbers[],int rotation){
for(int a=0;a<rotation;a++){
int x=numbers[arraylenth-1];
int j;
for(j=arraylenth-1 ;j>0;j--){
numbers[j]=numbers[j-1];
}
numbers[0]=x;
}
}

(GIVING grade to the student)


#include<iostream>
using namespace std;
int main(){

int x;
cout<<"exam number is."<<endl;
cin>>x;
if(x>80){
cout<<"grsde is A.."<<x<<endl;
}
else if((x>=61 && x<=80)){
cout<<"grade is B.."<<endl;
}
else if((x>=51 && x<=60)){
cout<<"grade is C.."<<x;
}
else if(x<40){
cout<<" FAIL.."<<x;}
}
(Week 6)
( array to find largest)

#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int num[3];
int largest=-1000;
for(int x=0;x<3;x++){if(num[x]>largest){
largest=num[x];}}
cout<<largest;

}
(ADMISSION management by array)
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
using namespace std;
int main(){

cout<<"*********************************************"<<endl;
cout<<"university admission management system"<<endl;
cout<<"*********************************************"<<endl;

string name[10];
float matric[10]={0,0,0,0,0,0,0,0,0,0};
float fsc[10]={0,0,0,0,0,0,0,0,0,0};
float ecat[10]={0,0,0,0,0,0,0,0,0,0};
float aggr[10];
int option;
int idx=0;
int largest=-1000;
int smallest=100;
int i=0;
while(option !=5)
{
system("CLS");
cout<<"1. add new student record "<<endl;
cout<<"2. view all record "<<endl;
cout<<"3. name and merit of top student"<<endl;
cout<<"4. name and merit of bottom student"<<endl;
cout<<"5. exist"<<endl;
cout<<"enter option ";
cin>>option;
if(option==1)
{

cout<<"enter name"<<endl;
cin>>name[idx];
cout<<"enter matric markd"<<endl;
cin>>matric[idx];

cout<<"enter fsc markd"<<endl;


cin>>fsc[idx];

cout<<"enter ecat markd"<<endl;


cin>>ecat[idx];

aggr[idx]=((matric[idx]/1100)*25)+((fsc[idx]/1100)*45)+((ecat[idx]/400)*30);

cout<<" aggrigate is "<<aggr[idx]<<endl;


idx=idx+1;
cout<<"press any word to continue"<<endl;
getch();
}

if(option==2){cout<<"NAME \t"<<"MATRIC \t"<<"FSC\t"<<"ECAT \t"<<"AGGRIGATE \t"<<endl;


for(int i=0;i<idx;i++){
cout<<name[i]<<"\t"<<matric[i]<<"\t"<<fsc[i]<<"\t"<<ecat[i]<<"\t"<<aggr[i]<<"\
t"<<endl;

}getch();}

if(option==3){
for(int i=0;i<idx;i++){
if(aggr[i]>largest){
largest=aggr[i];
}}cout<<largest;
getch();}

if(option==4){
for(int i=0;i<idx;i++){
if(aggr[i]<smallest){
smallest=aggr[i];
}}cout<<smallest;
getch();}

}}

(Week7)
(MENUE BY FUNCTION)
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
using namespace std;
int manue();
int number[100];
int counter=0;
int option;
void addnumber();
void printnumber();
int frequancy(int f);
int replace (int r,int s);
float average();
int odd();
int largest();
int main(){
int op=100;
while(op !=8){
system("CLS");
op=manue();
if (op==1){
addnumber();
}
if (op==2){
printnumber();
getch();
}
if (op==3){
int a;
cout<<"enter frequancy no"<<endl;
cin>>a;
int result=frequancy(a);

cout<<result<<endl;
getch();
}
if(op==4){
int b,c;
cout<<"checking number"<<endl;
cin>>b;
cout<<"replacing number"<<endl;
cin>>c;
replace(b,c);
cout<<"NUMBER IS CHANGED SUCESSFULLY";
getch();
}
if(op==5){
int result=average();
cout<<"average is"<<result<<endl;
getch();
}
if(op==6){
int larger=largest();
cout<<"larger is"<<larger<<endl;
getch();
}

}
}
void addnumber(){
int newnumber;
cout<<"enter number to add"<<endl;
cin>>newnumber;
number[counter]=newnumber;
counter=counter+1;
}
void printnumber(){
for(int idx=0 ;idx<counter;idx++){
cout<<number[idx]<<endl;

}
int frequancy(int f){
int result;
for(int idx=0 ;idx<counter;idx++){
if(number[idx]==f){
result=result+1;

}
return result;

}
int replace(int r,int s ){
for(int idx=0 ;idx<counter;idx++){
if(number[idx]==r){
number[idx]=s;

}
}
return 0;
}
float average(){
int sum=1;
int result;
for(int idx=0;idx<counter;idx++){
sum=sum+number[idx];
result=sum/counter;

}
return result;
}
int largest(){
int larger=-1;
for(int idx=0;idx<counter;idx++){
if(number[idx]>larger){
larger=number[idx];
}
}
return larger;

int manue(){
int option=100;
cout<<"select option"<<endl;
cout<<"1. add new no"<<endl;
cout<<"2. print number"<<endl;
cout<<"3. frequancy of no"<<endl;
cout<<"4. find and replace the no"<<endl;
cout<<"5. print the average of all no"<<endl;
cout<<"6. print the largest no"<<endl;
cout<<"7. print the sum of all no"<<endl;
cout<<"8. exist"<<endl;
cin>>option;
return option;
}

(these tasks done during HEC visit)

1.1.(total fare of bus)


#include<iostream>
#include <string>
using namespace std;
int main(){
string t1,t2,t3;
int f1,f2,f3;
int totalfaresum;
cout<<"enter name of transport 1_";
cin>>t1;
cout<<"enter fare of transport 1_";
cin>>f1;
cout<<"enter name of transport 2_";
cin>>t2;
cout<<"enter fare of transport 2_";
cin>>f2;
cout<<"enter name of transport 3_";
cin>>t3;
cout<<"enter fare of transport 3_";
cin>>f3;

totalfaresum=f1+f2+f3;
cout<<"total fare is"<<endl;
cout<<totalfaresum<<endl;
}

(1.2)
#include<iostream>
#include <string>
using namespace std;
int main(){
string t1,t2,t3;
int f1,f2,f3;
int total;
int km1,km2,km3;
cout<<"enter name of transport 1_";
cin>>t1;
cout<<"enter fare/km of transport 1_";
cin>>f1;
cout<<"enter km travelled by transport 1_";
cin>>km1;
cout<<"enter name of transport 2_";
cin>>t2;
cout<<"enter fare/km of transport 2_";
cin>>f2;
cout<<"enter km travelled by transport 2_";
cin>>km2;
cout<<"enter name of transport 3_";
cin>>t3;
cout<<"enter fare/km of transport 3_";
cin>>f3;
cout<<"enter km travelled by transport 3_";
cin>>km3;

total=f1*km1+f2*km2+f3*km3;
cout<<"total fare"<<total<<endl;

(2.1)
#include<iostream>
#include <string>
using namespace std;
int main(){
string t1,t2,t3;
int f1,f2,f3;
int total;
int km1,km2,km3;
int c1,c2,c3;
cout<<"enter name of transport 1_";
cin>>t1;
cout<<"enter fare/km of transport 1_";
cin>>f1;
cout<<"enter km travelled by transport 1_";
cin>>km1;
cout<<"enter name of transport 2_";
cin>>t2;
cout<<"enter fare/km of transport 2_";
cin>>f2;
cout<<"enter km travelled by transport 2_";
cin>>km2;
cout<<"enter name of transport 3_";
cin>>t3;
cout<<"enter fare/km of transport 3_";
cin>>f3;
cout<<"enter km travelled by transport 3_";
cin>>km3;
c1=f1*km1;
c2=f2*km2;
c3=f3*km3;
if(c1>c2 ||c1>c3){
cout<<t1<<c1<<endl;
}
else if(c2>c1 ||c2>c3){
cout<<t2<<c2<<endl;
}
else if(c3>c2 ||c3>c1){
cout<<t3<<c3<<endl;
}

(3.1)

#include<iostream>
#include <string>
using namespace std;
int main(){
string t1="taxi",t2="bus",t3="train";
string day="day";
string night="night";

int km;
string time;
float c1,c2,c3;

cout<<"enter the distance";


cin>>km;
cout<<"enter time";
cin>>time;
if(km<20 && time==day){
c1=(km*0.79)+0.70;
cout<<c1<<t1<<endl;
if(km<20 && time==night){
c1=(km*0.90)+0.70;
cout<<c1<<t1<<endl;

}
else if((km>20 && km<100) && (time==day ||time==night)){
c1=km*0.09;
cout<<c1<<t2<<endl;
}
else if(km>100 && (time==day ||time==night)){
c1=km*0.06;
cout<<c1<<t3<<endl;
}

(3.2)
#include<iostream>
#include <string>
using namespace std;
int main(){
string
d1="monday",d2="tuesday",d3="wednesday",d4="thirsday",d5="friday",d6="saturday",d7="su
nday";
string day;
string f1="apple",f2="banana",f3="orange",f4="grape",f5="kiwi";
string fruitname;
float qty;
float result;
cout<<"enter the day";
cin>>day;
cout<<"enter name of fruit ";
cin>>fruitname;
cout<<"enter quantity of fruit";
cin>>qty;

if(((day==d1) || (day==d2)|| (day==d3)||(day==d4)||(day==d5)) && (fruitname==f2)){


result=qty*2.50;
cout<<result<<endl; }

if(((day==d1) || (day==d2)|| (day==d3)||(day==d4)||(day==d5)) && (fruitname==f1)){


result=qty*1.20;
cout<<result<<endl; }

if(((day==d1) || (day==d2)|| (day==d3)||(day==d4)||(day==d5)) && (fruitname==f3)){


result=qty*0.85;
cout<<result<<endl; }

if(((day==d1) || (day==d2)|| (day==d3)||(day==d4)||(day==d5)) && (fruitname==f4)){


result=qty*1.45;
cout<<result<<endl; }

if(((day==d1) || (day==d2)|| (day==d3)||(day==d4)||(day==d5)) && (fruitname==f5)){


result=qty*2.70;
cout<<result<<endl;}
if(((day==d6) || (day==d7)) && (fruitname==f1)){
result=qty*1.25;
cout<<result<<endl;
}
if(((day==d6) || (day==d7)) && (fruitname==f1)){
result=qty*1.25;
cout<<result<<endl;
} if(((day==d6) || (day==d7)) && (fruitname==f2)){
result=qty*2.70;
cout<<result<<endl;
} if(((day==d6) || (day==d7)) && (fruitname==f3)){
result=qty*0.90;
cout<<result<<endl;
} if(((day==d6) || (day==d7)) && (fruitname==f4)){
result=qty*1.60;
cout<<result<<endl;
} if(((day==d6) || (day==d7)) && (fruitname==f5)){
result=qty*3.00;
cout<<result<<endl;
}

(4.1)
#include<iostream>
#include <string>
using namespace std;
int main(){
int x1,x2,y1,y2,x,y;

cout<<"enter x1 ";
cin>>x1;
cout<<"enter y1 ";
cin>>y1;
cout<<"enter x2 ";
cin>>x2;
cout<<"enter y2 ";
cin>>x1;
cout<<"enter x ";
cin>>x;
cout<<"enter y ";
cin>>y;

if((((x==x1) || (x==x2)) && ((y<=y1) && (y>=y2))) || (((y==y1) || (y==y2)) && ((x<=x1) &&
(x>=x2)))) {
cout<<"border";
}
else{
cout<<"inside or outside";
}}

(4.2)
#include<iostream>
#include <string>
using namespace std;
int main(){
string city;
int vsales;
float result;
string c1="lahore",c2="multan",c3="fsd";
cout<<"enter city name";
cin>>city;
cout<<"enter volume of sales";
cin>>vsales;
if(vsales<=500 && city==c1 ){
result=(vsales*5)/100;
cout<<result<<endl;
}
else if((vsales>500 && vsales<=1000) && (city==c1) ){
result=(vsales*7)/100;
cout<<result<<endl;
}
else if((vsales>1000 && vsales<=10000) && (city==c1) ){
result=(vsales*8)/100;
cout<<result<<endl;
}
else if(vsales>10000 && city==c1) {
result=(vsales*12)/100;
cout<<result<<endl;
}
//multan..

if(vsales<=500 && city==c2 ){


result=(vsales*4.5)/100;
cout<<result<<endl;
}
else if((vsales>500 && vsales<=1000) && (city==c2) ){
result=(vsales*7.5)/100;
cout<<result<<endl;
}
else if((vsales>1000 && vsales<=10000) && (city==c2) ){
result=(vsales*10)/100;
cout<<result<<endl;
}
else if(vsales>10000 && city==c2) {
result=(vsales*13)/100;
cout<<result<<endl;
}

//FSD..
if(vsales<=500 && city==c3 ){
result=(vsales*5.5)/100;
cout<<result<<endl;
}
else if((vsales>500 && vsales<=1000) && (city==c3) ){
result=(vsales*8)/100;
cout<<result<<endl;
}
else if((vsales>1000 && vsales<=10000) && (city==c3) ){
result=(vsales*12)/100;
cout<<result<<endl;
}
else if(vsales>10000 && city==c3) {
result=(vsales*14.5)/100;
cout<<result<<endl;
}

//error..
else{
cout<<"error";
}
}

(5.1)
#include<iostream>
using namespace std;
int main(){
int result;

int n,a,d;
cout<<"enter N";
cin>>n;
cout<<"enter A";
cin>>a;
cout<<"enter D";
cin>>d;
for(int x=1; x<=n;x++){
cout<<a<<",",
a=a+d;

(5.2)
#include <iostream>
using namespace std;
int main(){
int num;
int sum;
while(true){
cout<<"enter no";
cin>>num;

sum=sum+num;
if(sum<=100 && num !=-1){

cout<<sum<<endl;}
else{
return 0;
}

(6.1)
#include <iostream>
using namespace std;
int main(){
int n;
int y;
int leftsum=0;
int rightsum=0;
cout<<"enter no";
cin>>n;

for(int x=1 ; x<=n*2;x++){


cout<<"enter check no";
cin>>y;
if( x<=n){
leftsum=leftsum+y;

}
if(x>n){
rightsum=rightsum+y;

}
}
if(rightsum==leftsum){
cout<<"yes"<<" "<<"sum"<<leftsum<<endl;
}
else{
cout<<"no"<<" "<<"differ"<<leftsum-rightsum<<endl;
}

(7.1)
#include <iostream>
using namespace std;
int main(){
float num,term,count1,count2,count3,count4,count5;
cout<<"enter no of term"<<endl;
cin>>term;
for(int i=1 ; i<=term; i++){
cout<<"enter number";
cin>>num;
if(num<200){
count1=count1+1;
}
else if(num>200 && num<=400){
count2=count2+1;
}
else if(num>400 && num<600){
count3=count3+1;
}
else if(num>600 && num<800){
count4=count4+1;
}
else if(num>=800){
count5=count5+1;
}
}
cout<<count1/term*100<<endl;
cout<<count2/term*100<<endl;
cout<<count3/term*100<<endl;
cout<<count4/term*100<<endl;
cout<<count5/term*100<<endl;
}

(7.2)
#include <iostream>
using namespace std;
int main(){
int period;
int patient;
int treated=0;
int untreated=0;
int doc=7;
int sum=0;
int sum1=0;
int sum2=0;
int day=0;
cout<<"enter no of period"<<endl;
cin>>period;
for(int i=1 ; i<=period; i++){
cout<<"enter patient numbers";
cin>>patient;
day++;
if(day==4){
day=1;
}
if(day==1){
if(patient<=doc){
treated=treated+patient;
}
else{
treated=treated+doc;
untreated=untreated+(patient-doc);
}

}
if(day==2){
if(patient<=doc){
treated=treated+patient;
}
else{
treated=treated+doc;
untreated=untreated+(patient-doc);
}
}
if(day==3){
if(untreated>0){
doc++;

if(patient<=doc){
treated=treated+patient;
}
else{
treated=treated+doc;
untreated=untreated+(patient-doc);
}
}

if(untreated==0){
if(patient<=doc){
treated=treated+patient;
}
else{
treated=treated+doc;
untreated=untreated+(patient-doc);
}

}
}
}
cout<<treated<<endl;
cout<<untreated<<endl;
}

(unit converter extended )


#include <iostream>

#include <string>

#include <stdlib.h>

#include <conio.h>

using namespace std;

const int ruleSize=10;

const int historySize=5;

//Global Variables

string largerunit[ruleSize];

string smallerunit[ruleSize];

float converter[ruleSize];

int currentRule=0; //that has been added

int currentHistory=0;

string history[historySize];

//Function Headers.

int getUserOption();
void addConversionRule();

void convertValue();

bool isRuleExist(string valueunit,string convertingunit);

float getMultiplier(string valueunit,string convertingunit);

void addHistory(string message);

void viewAllRules();

void pressKey();

void viewHistory();

string getLogMessage(float value,string valueunit,string convertingunit,float newValue);

int main(){

int option=-1;

while (option !=5) {

system("CLS");

option= getUserOption();

if(option==1){

addConversionRule();

if(option==2){

viewAllRules();

getch();

pressKey();

if(option==3){

convertValue();

pressKey();

if(option==4){
viewHistory();

pressKey();

if(option==5){

return 0;

} //end while loop

} //end main method

int getUserOption(){

int option=-1;

cout<<"************************************************"<<endl;

cout<<" Unit Converter "<<endl;

cout<<"************************************************"<<endl;

cout<<"1. Add Conversion Rule"<<endl;

cout<<"2. Show All Conversion Rules"<<endl;

cout<<"3. Convert the Value"<<endl;

cout<<"4. Show History"<<endl;

cout<<"5. Exit"<<endl;

cout<<"Enter Your Option..";

cin>>option;

return option;

void addConversionRule(){

cout<<"enter largerunit";
cin>>largerunit[currentRule];

cout<<"enter smallerunit";

cin>>smallerunit[currentRule];

cout<<"enter convert rule";

cin>>converter[currentRule];

currentRule=currentRule+1;

void viewAllRules(){

cout<<"Largerunit \t"<<"Smallerunit \t"<<"Converter\t"<<endl;

for(int idx=0;idx<currentRule;idx=idx+1){

cout<<largerunit[idx]<<" \t"<<smallerunit[idx]<<" \t"<<converter[idx]<<endl;

}
}

void convertValue(){

float value;

string valueunit;

string convertingunit;

cout<<"enter vaqlue to convert"<<endl;

cin>>value;

cout<<"enter unit of value"<<endl;

cin>>valueunit;

cout<<"enter value to convert"<<endl;

cin>>convertingunit;

if(isRuleExist( valueunit,convertingunit)){

float multiplier=getMultiplier(valueunit,convertingunit);

float newvalue=value*multiplier;

string message= getLogMessage( value, valueunit, convertingunit, newvalue);

cout<<message<<endl;

addHistory( message);

getch();

}
bool isRuleExist(string valueunit,string convertingunit){

for(int idx=0;idx<currentRule;idx++){

if((valueunit==largerunit[idx]) && (convertingunit==smallerunit[idx])){

return true;

if((valueunit==smallerunit[idx]) && (convertingunit==largerunit[idx])){

return true;

return false;

float getMultiplier(string valueunit,string convertingunit){

for(int idx=0;idx<10;idx++){

if((valueunit==largerunit[idx]) && (convertingunit==smallerunit[idx])){

return converter[idx];

if((valueunit==smallerunit[idx]) && (convertingunit==largerunit[idx])){

return (1/converter[idx]);
}

return 0;

void addHistory(string message){

history[currentHistory] = message;

currentHistory++;

void viewHistory(){

for(int x=0;x<historySize;x++){

cout<<history[x]<<endl;

}getch();

void pressKey(){

cout<<endl;

cout<<"press any word to continue";

string getLogMessage(float value,string valueunit,string convertingunit,float newvalue){

string hist=to_string(value)+" "+(valueunit)+" converting to "+to_string(newvalue)+" "+


(convertingunit);

return hist;

}
(week 9)

(file palodorian)
#include <iostream>
#include <cstring>
using namespace std;
int main(){
// initiallixing the character array by
char name [30];
cout<<"enter the name or number"<<endl;
cin>>name;
//initializing the variable
int i=0 ,j= strlen (name)-1 ;
bool x=true;
for(i=0 ;i<j ;i++ ){
if(name[i] !=name[j]){
x=false;
}
j--;
}
if(x){
cout<<"the string is paladromine \n"<<endl;
}
else{
cout<<"not paladromine"<<endl;
}
}

(SIGN IN -up )
#include <iostream>
#include <fstream>
using namespace std;
void signin();
void signup();
int main(){
int option=1000;
while(option!=3){
cout<<"1. signup"<<endl;
cout<<"2. signin"<<endl;
cout<<"enter your option "<<endl;
cin>>option;
if(option==1){
signup();
}
if(option==2){
signin();
}

}
void signin(){

fstream newfile;
string name ;
string pin;
cout<<"enter your name"<<endl;
cin>>name;
cout<<"enter password"<<endl;
cin>>pin;

newfile .open("textfile.text1" ,ios::in);

string data ,data2;


bool isusernameexist=false;
while(getline(newfile,data) && getline(newfile,data2)){

if (data==name && data2==pin) {


isusernameexist=true;
}

}
if( isusernameexist){
cout<<"valid"<<endl;
}
else{
cout<<"invalid"<<endl;
}
newfile.close();

}
void signup(){
fstream newfile;
string username ,pin ;
newfile .open("textfile.text1" ,ios::app);
cout<<"enter your name"<<endl;
cin>>username;
cout<<"enter your pin"<<endl;
cin>>pin;
newfile<<username<<endl;

newfile<<pin<<endl;

newfile .close();

(ums by file system)


#include <iostream>
#include <fstream>
using namespace std;
void signin();
void signup();
int main(){
int option=1000;
while(option!=3){
cout<<"1. signup"<<endl;
cout<<"2. signin"<<endl;
cout<<"enter your option "<<endl;
cin>>option;
if(option==1){
signup();
}
if(option==2){
signin();
}

}
void signin(){

fstream newfile;
string name ;
string pin;
cout<<"enter your name"<<endl;
cin>>name;
cout<<"enter password"<<endl;
cin>>pin;

newfile .open("textfile.text1" ,ios::in);

string data ,data2;


bool isusernameexist=false;
while(getline(newfile,data) && getline(newfile,data2)){

if (data==name && data2==pin) {


isusernameexist=true;
}

}
if( isusernameexist){
cout<<"valid"<<endl;
}
else{
cout<<"invalid"<<endl;
}
newfile.close();

}
void signup(){
fstream newfile;
string username ,pin ;
newfile .open("textfile.text1" ,ios::app);
cout<<"enter your name"<<endl;
cin>>username;
cout<<"enter your pin"<<endl;
cin>>pin;
newfile<<username<<endl;

newfile<<pin<<endl;

newfile .close();

(find the length of string)


#include <iostream>
#include <string.h>
using namespace std;
int main(){
string s;
cin>>s;

int length=0;
length=s.length();
cout<<length<<endl;
}

(studying char array)


#include <iostream>
using namespace std;
int main(){
char word [6]={'h','e','l','l','o'};
cout<< word[4]<<endl;
}

(writing name in urdu in file)


#include <iostream>
using namespace std;
int main(){

string str ="\u0645\u06CC\n\u0633\u06A9\u0648\u0644";


cout<<str<<endl;
}
(week 10)

(printing-words-by-using-file)
#include <iostream>
#include <fstream>
using namespace std;
int main(){
fstream newfile;
newfile .open("textfile.text" ,ios::in);
string data;
while(getline(newfile,data)){
if ((data[0]=='A' || data[0]=='a') && data.length()==3){
cout<<data<<endl;
}
else{
cout<<"notfound"<<endl;
}
}
newfile.close();

(read-from-file-and-write-on-compiler)
#include <iostream>
#include <fstream>
using namespace std;
int main(){
fstream newfile;
newfile .open("textfile.text" ,ios::in);
string data;
while( getline(newfile,data)){
cout<<data<<endl;
}

(writing-word-in-file)
#include <iostream>
#include <fstream>
using namespace std;
int main(){
fstream newfile;
newfile .open("textfile.text" ,ios::out);
newfile<<"hello \n";
newfile<<"me to tekh ho sir ap sunae";
newfile<<"ant \n";
newfile<<"Anthello \n";
newfile<<"aAhello \n";
newfile<<"aak \n";
newfile<<"khamsh ho jao\n";
newfile .close();

}
(project by file system is separately hard
copied)

(week 10 end)
(week 11)

(TIC TAC GAME)


#include <iostream>
using namespace std;
const int gridsize=3;
bool checkallrows(char symbol);
bool checkallcolumn(char symbol);
bool checkleftdiagnol(char symbol);
bool checkrightdiagnol(char symbol);
bool iswin(char symbol);
void showgame();
void getinput();
void changeplayer();
char board[gridsize][gridsize]={{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};

int main(){

getinput();

if(iswin('x')==true){
cout<<"x is winner"<<endl;
}
else if(iswin('o')==true){
cout<<"o is winner"<<endl;
}

else{
cout<<"match is draw"<<endl;
}
}
void showgame(){

for(int i=0 ;i<gridsize; i++){

for(int j=0; j<gridsize; j++ ){


cout<<board[i][j] <<" ";
}
cout<< endl;
}

void getinput(){
system("CLS");

int a;
int b;
for(int i=0 ; i<9; i++){
system("CLS");
showgame();
if (i%2 ==0){
cout<<"enter yor turn x"<<endl;
cin>>a;
if(a==1){
board[0][0]='x';}
else if(a==2){board[0][1]='x';}
else if(a==3){board[0][2]='x';}
else if(a==4){board[1][0]='x';}
else if(a==5){board[1][1]='x';}
else if(a==6){board[1][2]='x';}
else if(a==7){board[2][0]='x';}
else if(a==8){board[2][1]='x';}
else if(a==9){board[2][2]='x';}
}

else if(i%2 !=0){


cout<<"enter yor turn o"<<endl;
cin>>b;
if(b==1){
board[0][0]='o';}
else if(b==2){board[0][1]='o';}
else if(b==3){board[0][2]='o';}
else if(b==4){board[1][0]='o';}
else if(b==5){board[1][1]='o';}
else if(b==6){board[1][2]='o';}
else if(b==7){board[2][0]='o';}
else if(b==8){board[2][1]='o';}
else if(b==9){board[2][2]='o';}
}
}

bool checkallrows(char symbol){


int counter=0;
for(int i=0 ;i<gridsize; i++){
counter=0;
for(int j=0; j<gridsize; j++ ){
if(board[i][j]==symbol){
counter++;
}
}
}
if(counter==3){
return true;
}
return false;

bool checkallcolumn(char symbol){


int counter=0;
for(int i=0 ;i<gridsize; i++){
counter=0;
for(int j=0; j<gridsize; j++ ){
if(board[j][i]==symbol){
counter++;
}
}
}
if(counter==3){
return true;
}
return false;

bool checkleftdiagnol(char symbol){


int counter=0;
for(int idx=0 ;idx<gridsize; idx++){
counter=0;
if(board[idx][idx]==symbol){
counter++;
}
}
if(counter==3){
return true;
}
return false;

bool checkrightdiagnol(char symbol){


int counter=0;
int j=2;
for(int i=0 ;i<gridsize; i++){
counter=0;

if(board[j][i]==symbol){
counter++;
}
j-- ;
}
if(counter==3){
return true;
}
return false;

bool iswin(char symbol){


if(checkallrows(symbol)||checkallcolumn(symbol)||checkleftdiagnol(symbol)||
checkrightdiagnol(symbol)){
return true;
}
return false;
}

(pacman game )
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <fstream>
#include<windows.h>
using namespace std;
const int gridsize1=16;
const int gridsize2=78;
int ghostx=4;
int ghosty=2;
int ghostx1=40;
int ghosty1=4;
void gotoxy( short x, short y );

char board[gridsize1][gridsize2]={};
int count=0;
int pmanx=7;
int pmany=14;
int leftLimit=0;
int rightLimit=20;

string ghostDirection="Right";
void loadgame();
void displaygame();
void movePacmanLeft();
void movePacmanRight();
void movePacmanUP();
void movePacmanDown();
void moveGhost();
void moveGhost1();
int main(void) {
system("CLS");
loadgame();
displaygame();

int x=2;
int key=4000;

bool gameRunning=true;
//showing pacman
gotoxy(pmanx,pmany);
cout<<"P";
while(gameRunning){
//scii codee for escape
if((pmanx==ghostx) && (pmany==ghosty)){
break;
}

if((pmanx==ghostx1) && (pmany==ghosty1)){


break;
}
if(GetAsyncKeyState( VK_LEFT )){ //ascii LEFT arrow
movePacmanLeft();
}
if(GetAsyncKeyState( VK_RIGHT )){ //ascii right arrow
movePacmanRight();
}

if(GetAsyncKeyState( VK_UP )){ // up arrow key


movePacmanUP();
}
if(GetAsyncKeyState( VK_DOWN)){ //down arrow key
movePacmanDown();
}
if(GetAsyncKeyState( VK_ESCAPE) ){
gameRunning=false;
}

moveGhost();
moveGhost1();
Sleep(200);

void loadgame(){
fstream newfile;
newfile.open("pacman.text" ,ios::in);
string data;
int x=0;
while (getline(newfile,data)){
for(int i=0; i<gridsize2; i++){
board[x][i]=data[i];
}
x++;

newfile.close();
}

void displaygame(){
for(int x=0; x<gridsize1;x++){
for(int y=0; y <gridsize2; y++){
cout<<board[x][y];

}
cout<<endl;

void movePacmanUP(){
gotoxy(pmanx,pmany);
cout<<" ";
int test=0;
pmany--;
test=board[pmany][pmanx];

if((test==35) || (test==37) || (test==124) ||( test==38 )){

pmany=pmany+1;
}

if(test==46){
count=count+1;
gotoxy(0,16);
cout<<"SCORE IS"<<"="<<count<<endl;
}
gotoxy(pmanx,pmany);
cout<<"P"<<endl;

void movePacmanDown(){
gotoxy(pmanx,pmany);
cout<<" ";
int test=0;
pmany++;
test=board[pmany][pmanx];
if((test==35) || (test==37) || (test==124) ||( test==38 )){

pmany=pmany-1;
}

if(test==46 ){
count=count+1;
gotoxy(0,16);
cout<<"SCORE IS"<<"="<<count<<endl;
}
gotoxy(pmanx,pmany);
cout<<"P"<<endl;

void movePacmanRight(){
gotoxy(pmanx,pmany);
cout<<" ";
int test;
pmanx++;
test=board[pmany][pmanx];
if((test==35) || (test==37) || (test==124) ||( test==38 )){

pmanx=pmanx-1;
}

if(test==46){
count=count+1;
gotoxy(0,16);
cout<<"SCORE IS "<<"="<<count<<endl;
}
gotoxy(pmanx,pmany);
cout<<"P"<<endl;

void movePacmanLeft(){
gotoxy(pmanx,pmany);
cout<<" ";
int test;
pmanx--;
test=board[pmany][pmanx];
if((test==35) || (test==37) || (test==124) ||( test==38 )){
pmanx=pmanx+1;
}

if(test==46 ){
count=count+1;
gotoxy(0,16);
cout<<"SCORE IS "<<"="<<count<<endl;

}
gotoxy(pmanx,pmany);
cout<<"P"<<endl;

}
////move ghost
void moveGhost(){
int Gposition;
gotoxy( ghostx, ghosty );
cout<<".";
board[ghosty][ghostx]='.';
if(pmany>ghosty){
ghosty++;
Gposition=board[ghosty][ghostx];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghosty=ghosty-1;
}
else{
ghostDirection="down";

if(pmany<ghosty){
ghosty--;
Gposition=board[ghosty][ghostx];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghosty=ghosty+1;
}
else{
ghostDirection="up";

if(pmanx>ghostx){
ghostx++;
Gposition=board[ghosty][ghostx];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghostx=ghostx-1;
}
else{
ghostDirection="Right";

if(pmanx<ghostx){
ghostx--;
Gposition=board[ghosty][ghostx];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghostx=ghostx+1;
}
else{
ghostDirection="left";

}
gotoxy( ghostx, ghosty );
cout<<"G";

////move ghost 2
void moveGhost1(){
int Gposition;
gotoxy( ghostx1, ghosty1 );
cout<<".";
board[ghostx1][ghosty1]='.';
if(pmany>ghosty1){
ghosty1++;
Gposition=board[ghosty1][ghostx1];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghosty1=ghosty1-1;
}
else{
ghostDirection="down";

}
if(pmany<ghosty1){
ghosty1--;
Gposition=board[ghosty1][ghostx1];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghosty1=ghosty1+1;
}
else{
ghostDirection="up";

if(pmanx>ghostx1){
ghostx1++;
Gposition=board[ghosty1][ghostx1];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghostx1=ghostx1-1;
}
else{
ghostDirection="Right";

}
}

if(pmanx<ghostx1){
ghostx1--;
Gposition=board[ghosty1][ghostx1];
if((Gposition==35) || (Gposition==37) || (Gposition==124) ||( Gposition==38 )){
ghostx1=ghostx1+1;
}
else{
ghostDirection="left";

}
gotoxy( ghostx1, ghosty1 );
cout<<"g";

}
////gotoxy function

void gotoxy( short x, short y )


{
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE) ;
COORD position = { x, y } ;
SetConsoleCursorPosition( hStdout, position ) ;
}

(Week 11 end)
(week 12)

(2dsorted-every-row)
#include <conio.h>
#include <iostream>
using namespace std;
void sortrowwise(int board[4][4],int row,int column);
int main(){
int board[4][4]={
{1,7,8,9},
{2,0,3,7},
{2,3,5,9},
{2,1,3,6}
};
//row is 4
//column is 4 that we pass to the function

sortrowwise(board,4, 4);
return 0;
}

void sortrowwise(int board[4][4],int row,int column){


for(int i=0;i<row;i++ ){ //for row
for(int j=0; j<column;j++){//for column
for(int k=0;k<column-j-1;k++){ //for comparison
if(board[i][k] < board[i][k+1]){
int partiallysave = board[i][k];
board[i][k] = board[i][k+1];
board[i][k+1] = partiallysave;
}
}
}
}
cout<<endl;
cout<<"show sorted matrix "<<endl;
for(int i=0; i<row; i++){
for(int j=0; j<column; j++){
cout<<board[i][j]<<" ";
}
cout<<endl;
}

(2D array sorted whole matrix)


#include <conio.h>
#include <iostream>
using namespace std;
void sortingmatrix( int board[4][4]);
int sorted[4][4];
int main(){

int board[4][4]={
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}
};
sortingmatrix(board);
}

void sortingmatrix(int board[4][4]){

for(int x =0;x<4;x++){
for(int y=0;y<4;y++){
int largest=-1000;
int largesti=-1000;
int largestj=-1000;

for(int i=0;i<4;i++){
for(int j=0; j<4; j++){
if(board[i][j]>largest){
largest=board[i][j];
largesti=i;
largestj=j;

}
}
}
board[largesti][largestj]=-10000;
sorted[x][y]=largest;
}
}

cout<<endl;
cout<<"show sorted matrix "<<endl;
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
cout<<sorted[i][j]<<" ";
}
cout<<endl;
}

(adding-pointer-adress)
#include <iostream>
using namespace std;
int main(){
int a;
int b;
cout<<"enter 1st no"<<endl;
cin>>a;

cout<<"enter 2st no"<<endl;


cin>>b;
int *pointera=&a;
int *pointerb=&b;

cout<< *pointera + *pointerb<<endl;

(file2dtranspose)
#include <conio.h>
#include <iostream>
using namespace std;

int board1[3][3] ;

int main(){
cout<<"enter element for 1stmatrix"<<endl;
for(int i=0 ;i<3;i++){
for(int j=0; j<3; j++){
cin>>board1[i][j];

}
cout<<endl;
cout<<"enter transpose of matrix"<<endl;
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
cout<<board1[j][i]<<" ";
}
cout<<endl;
}
return 0;

(pointer_to_print_adress)
#include <iostream>
using namespace std;
int main(){

float value1=2.5;
float *pointervalue1=&value1;
float value2=3.5;
float *pointervalue2=&value2;

float value3=4.5;
float *pointervalue3=&value3;

cout<<pointervalue1<<endl ;
cout<<pointervalue2 <<endl ;
cout<<pointervalue3 <<endl ;
}

(sum of 2D matrix)
#include <conio.h>
#include <iostream>
using namespace std;

int board1[4][3] ;
int board2[4][3] ;
int main(){
cout<<"ENTER ELEMENT OF 1st MATRIX"<<endl;
cout<<endl;
cout<<endl;
for(int i=0 ;i<4;i++){
for(int j=0; j<3; j++){
cout<<"enter element in row "<<i+1<<" colum"<<j+1<<":";
cin>>board1[i][j];

}
cout<<endl;
cout<<endl;
cout<<"ENTER ELEMENT OF 2st MATRIX"<<endl;
cout<<endl;
cout<<endl;
for(int i=0 ;i<4;i++){
for(int j=0; j<3; j++){
cout<<"enter element in row "<<i+1<<" colum"<<j+1<<":";

cin>>board2[i][j];

}
}

cout<<endl;
cout<<"enter sum of matrix"<<endl;
for(int i=0; i<4; i++){
for(int j=0; j<3; j++){
cout<<board1[i][j]+board2[i][j]<<" ";
}
cout<<endl;
}
return 0;

You might also like