Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

Thursday, 18 April 2019

Check whether a given number is Automorphic number or not

// C program to check whether the number is automorphic or not
#include<stdio.h>
bool isAutomorphic(int N)
{
int sq = N * N;
while (N > 0)
{
if (N % 10 != sq % 10)
return false;
// Reduce N and square
N /= 10;
sq /= 10;
}
return true;
}
int main()
{
//Fill the code
int N;
scanf(“%d”,&N);
isAutomorphic(N) ? printf(“Automorphic”) : printf(“Not Automorphic”);
return 0;
}

Program to check if a given number is a strong number or not

Program to check if a given number is a strong number or not is discussed here. A strong number is a number in which the sum of the factorial of the digits is equal to the number itself.
check if a given number is strong number or not
#include<bits/stdc++.h>
using namespace std;
int fact(int num)
{
int res=1;
while(num>0)
{
res*=(num--);
}
return res;
}
bool isStrong(int num)
{
int p=num;
int res=0;
while(p>0)
{
res+=fact(p%10);
p/=10;
}
if(res==num)
return 1;
return 0;
}



int main()
{
int num=123;
cout<<isStrong(num);
}

Program to Find if number is Armstrong Number or Not in C++ C

#include<bits/stdc++.h>
using namespace std;
bool isArm(int num)
{
int ans=0;
int p=num;
while(num>0)
{
int x=num%10;
ans+=x*x*x;
num/=10;
}
if(p==ans)
return 1;
return 0;
}
int main()
{
cout<<isArm(371);
}

Program to check number is Prime or Not in C++

#include<bits/stdc++.h>
using namespace std;
bool isPrime(int num)
{
int p=num;
if(num%2==0)
return 0;
for(int i=3;i*i<=p;i+=2)
{
if(num%i==0)
return 0;
}
return 1;
}

int main()
{
int num=91;
cout<<isPrime(num);
}

LCM of Two Number Program in C++

// LCM of two number is a*b divided by gcd/hcf of two number
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
int lcm=(a*b)/__gcd(a,b);
cout<<lcm;
}

Program to Calculate GCD or HCF of Two Numbers in C++ (No STL)

// mail me @ mujtaba.aamir1@gmail.com for c++,python notes for free.....
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int __gcd(int a,int b)
{
if(b==0)
return a;
return __gcd(b,a%b);
}
int main()
{
int a=12;
int b=6;
cout<<__gcd(a,b);
}

String to Char Array and Char Array to String Conversion in C++ Simple Approch

#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main()
{
char s[]="stringwith-hyphen";
int size=sizeof(s)/sizeof(s[0]);
char ch[size];
int j=0;
for(int i=0;i<size;i++)
{
if(s[i]=='-')
ch[j++]=s[i];
}
for(int i=0;i<size;i++)
{
if(s[i]!='-')
ch[j++]=s[i];
}
for(int i=0;i<size;i++)
s[i]=ch[i];

// Char Array to String conversion using constructor
// Method 1

string s1(s);

// Method 2

string s2="";
for(int i=0;i<size;i++)
s2+=s[i];
printf("%s\n",s);
cout<<s2;


}

Sunday, 25 November 2018

Count All Increasing Sub Sequences GeeksForGeeks Python Program

for _ in range(int(input())):
    n=int(input());
    l=list(map(int,input().split()));
    lz=[0]*10;
    for i in range(len(l)):
        for j in range(l[i]-1,-1,-1):
            lz[l[i]]+=lz[j];
        lz[l[i]]+=1;
    print(sum(lz));
    
    

Thursday, 15 November 2018

Longest Increasing Sub Sequences with Dynamic Programming in Python | C++ | C

# Author Mohd Mujtaba @ Play with C Plus
def LIS(l):
    n=len(l);
    l1=[1]*n;
    for i in range(n):
        for j in range(0,i):
            if(l[i]>l[j]):
                l1[i]=max(l1[j]+1,l1[i]);
    print(max(l1));
for _ in range(int(input())):
    n=int(input());
    l=list(map(int,input().split()));
    LIS(l);
   

Monday, 8 October 2018

Insertion, Deletion ,Searching at First ,Last , At Given Position in Linked List Implementation in C++

#include<bits/stdc++.h>
using namespace std;
struct node
{
node *link;
int data;
}*start=NULL;
// INSERTION INTO LINKED LIST
void insertNode(int data)
{
node *temp=new node;
temp->link=NULL;
temp->data=data;
if(start==NULL)
{
start=temp;
return;
}
else
{
node *ptr=start;
while(ptr->link!=NULL)
{
ptr=ptr->link;
}
ptr->link=temp;
}
}
void insertInBetween(int data,int search)
{
node *temp=new node;
temp->data=data;
temp->link=NULL;
node *ptr=start;
while(ptr->link!=NULL and ptr->data!=search)
ptr=ptr->link;
temp->link=ptr->link;
ptr->link=temp;
}
void insertFirst(int data)
{
node *temp=new node;
temp->data=data;
temp->link=start;
start=temp;
}
void insertInBetweenBefore(int data,int search)
{
node *prev=NULL,*ptr=start,*temp=new node;
temp->data=data;
while(ptr->link!=NULL and ptr->data!=search)
{
prev=ptr;
ptr=ptr->link;
}
temp->link=prev->link;
prev->link=temp;
}

// ?? VARIOUS LINKED LIST DELETION OPERATIONS ?? //
void deleteFirst()
{
node *ptr=start;
if(ptr->link==NULL)
start=NULL;
else
start=ptr->link;

delete(ptr);
}
void deleteAtPosition(int pos)
{
node *ptr=start;
node *prev=NULL;
int count=0;
while(ptr->link!=NULL and count!=pos)
{
prev=ptr;
count+=1;
ptr=ptr->link;
}
prev->link=ptr->link;
delete(ptr);
}

void deleteLast()
{
node *ptr=start,*prev=NULL;
while(ptr->link!=NULL)
{
prev=ptr;
ptr=ptr->link;
}
prev->link=NULL;
delete(ptr);
}

void disp()
{
node *ptr=start;
while(ptr!=NULL)
{
cout<<" -->"<<ptr->data;
ptr=ptr->link;
}
}

int main()
{
insertNode(10);
insertNode(20);
insertNode(30);
insertNode(40);
cout<<"BEFORE\n";
disp();
cout<<"\nINSERTION AFTER 30\n";
insertInBetween(35,30);
disp();
cout<<"\nINSERTION AT FIRST NODE\n";
insertFirst(5);
disp();
cout<<"\nINSERTION BEFORE 30\n";
insertInBetweenBefore(25,30);
disp();
cout<<"\nDELETING FIRST ELEMENT\n";
deleteFirst();
disp();
cout<<"\nDELETING AT GIVEN POSITION =3:\n";
deleteAtPosition(3);
disp();
cout<<"\nDELETING LAST ELEMENT:\n";
deleteLast();
disp();


}

Sunday, 1 July 2018

Pizza Hut Management System Project in C++

//This Program Is Created By Mohd Mujtaba Section-K1613 Roll No-B47 Reg No-11608125

//*******************************PROGRAM STARTS FROM HERE*********************************************
#include<iostream> // can be remove when using fstream
#include<fstream>
#include<conio.h> // getch()
#include<stdio.h> // gets,puts, 
#include<stdlib.h> // system("cls") system("PAUSE") exit() remove() rename()
#include<string.h> // strcpy strlen strcmp etc..
#include<iomanip>
#include<windows.h>   //Sleep()
#include<bits/stdc++.h>

using namespace std;

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // used for goto
COORD CursorPosition; 

void gotoxy(int x,int y)
{
CursorPosition.X=x;
CursorPosition.Y=y;
SetConsoleCursorPosition(console,CursorPosition); 

}

using namespace std;
fstream f1;
fstream f2;
fstream f3;
fstream f4;


int i,temp,found=0,total=0;
char chop='y';
int i_code1;



class menu
{
protected:
float price;
char p_name[20];
public:
int i_code;
void get_menu();
void show_menu();
void delPizzaMenu();
};
class order: public menu
{
protected:
char name[30],add[80];
int bill_no,i_code2;
long long mbno;
public:
void modify();

void get_order();
void show_order();
void gen_bill(int,int);
void search();
void del_rec();

};

class lovely_pizza:public order
{
public:




void home_page()
{

int menuch=1;
bool value=true;
int x=7;
// MENU:



while(value)
{
system("cls");
gotoxy(14,x);
cout<<"->";
system("color 1A");
gotoxy(18,1);
cout<<setw(30)<<"             ==================================================";
gotoxy(18,2);
// Sleep(150);
cout<<setw(30)<<"                      WELCOME TO LOVELY PIZZA PVT. LTD. ";
gotoxy(18,4);
// Sleep(150);
cout<<setw(30)<<"                               PHAGWARA PUNJAB";
gotoxy(18,5);
// Sleep(150);
cout<<setw(30)<<"            ===================================================";
gotoxy(18,6);
// Sleep(100);
gotoxy(18,7);
cout<<"1. NEW ORDER:";
gotoxy(18,8);
cout<<"2. ALL ORDER DETAILS:";
gotoxy(18,9);
cout<<"3. SEARCH ORDER";
gotoxy(18,10);
cout<<"4. Modify ORDER:";
gotoxy(18,11);
cout<<"5. Delete ORDER :";
gotoxy(18,12);
cout<<"6. Enter Pizza Menu Details:";
gotoxy(18,13);
cout<<"7. Show Pizza  MENU:";
gotoxy(18,14);
cout<<"8. Delete Pizza Details:";
gotoxy(18,15);
cout<<"9. Exit (Sign Out):";
gotoxy(18,16);
cout<<"Choose One Option...... :";
system("pause>nul"); // the >nul bit causes it the print no message

if(GetAsyncKeyState(VK_DOWN) && x != 16)
{
gotoxy(14,x);
cout<<"  ";
x++;
cout<<"->";
menuch++;
continue;
}
if(GetAsyncKeyState(VK_UP)&&x!=7)
{
gotoxy(14,x);
cout<<"  ";
x--;
cout<<"->";
menuch--;
continue;
}
if(GetAsyncKeyState(VK_RETURN))
{

switch(menuch)
{
case 1:
system("cls");

get_order();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
case 2:
system("cls");
f2.open("D:/order.txt",ios::in|ios::out|ios::app);
show_order();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
case 3:
search();
cout<<"Press Again Any Key...#BACK #TO #MENU:";
getch();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
case 4:
system("cls");
modify();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
    case 5:
    del_rec();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
     
case 6:

        f1.open("D:\\menu.txt",ios::out|ios::app);
    get_menu();
f1.close();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
case 7:
system("cls");
    f1.open("D:/menu.txt");
    show_menu();
    f1.close();
    getch();
    // goto MENU; // REDIRECTED TO MENU LABEL
    break;
case 8:
delPizzaMenu();
// goto MENU; // REDIRECTED TO MENU LABEL
break;
case 9:
system("cls");

for(i=0;i<50;i++)
{

cout<<"/";
if(i==26)
cout<<"Saving And Exiting.....:";
Sleep(30);
}

exit(42);
value=false;

}
}
}
gotoxy(18,19);
}

}pizza;

void menu::get_menu()
{
system("color 2F");
do
{
system("cls");
cout<<setw(30)<<"Enter All Pizza DETAILS With PRICES:\n\n";
cout<<"Enter Item Code:";
fflush(stdin);
    
cin>>i_code;
cout<<"Pizza Name;";
fflush(stdin);
gets(p_name);
cout<<"Price:";
cin>>price;
f1.write((char*)&pizza,sizeof(pizza));
system("cls");
cout<<"Record Entered.......\n"<<setw(15)<<"Want To Enter Any More (Y/N):";
cin>>chop;

}while(chop=='y'||chop=='Y');
}

void menu::show_menu()
{
system("color 1A");
cout<<"Item_Code"<<setw(18)<<"Name"<<setw(25)<<"Price"<<"\n";
while(f1.read((char*)&pizza,sizeof(pizza)))
cout<<i_code<<setw(25)<<p_name<<setw(20)<<price<<"\n";
}

void order::modify()
{
MODIFY:
found=0;
int mbno1,x;
char cnfModify;
cout<<"Enter Mobile_No:";
cin>>mbno1;
f2.open("D:\\order.txt",ios::in|ios::out|ios::app);
f3.open("D:\\order1.txt",ios::in|ios::out|ios::app);


cout<<"Bill_No:"<<setw(10)<<"Name"<<setw(20)<<"Address"<<setw(20)<<"Mobile No"<<setw(20)<<"Pizza Code"<<"\n";
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(mbno1==mbno)
{
cout<<bill_no<<setw(20)<<name<<setw(20)<<add<<setw(15)<<mbno<<setw(20)<<i_code2<<"\n";
//
//
cout<<"\nWant To Modify This:(Y/y):";
fflush(stdin);
cin>>cnfModify;
fflush(stdin);
if(cnfModify=='y'||cnfModify=='Y')
{
cout<<"\nEnter New Pizza Code:";
cin>>i_code2;

}
f3.write((char*)&pizza,sizeof(pizza));
found=1;
}


}
if(found==0)
{
cout<<"File Not Found!!! ENTER AGAIN::";
system("PAUSE");
f2.close();
    f3.close();
goto MODIFY;
}

f2.close();
f3.close();



f2.open("D:\\order.txt",ios::in|ios::out|ios::app);
f3.open("D:\\order1.txt",ios::in|ios::out|ios::app);
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(mbno1==mbno)
continue;
else
f3.write((char*)&pizza,sizeof(pizza));
}
f2.close();
f3.close();
remove("D://order.txt");
rename("D://order1.txt","D://order.txt");

cout<<"\n\n Record Updated!! Press Any Key For MENU";
getch();
}

void order::get_order()
{
    int x,tempBillCount=0;
char ch;
f2.open("D:\\order.txt",ios::out|ios::in|ios::app);
while(f2.read((char*)&pizza,sizeof(pizza)))
{
tempBillCount++;

}
f2.close();
f2.open("D:\\order.txt",ios::out|ios::in|ios::app);
bill_no=tempBillCount+1;
cout<<"Enter Name:";
fflush(stdin);
gets(name);
cout<<"Enter Address:";
fflush(stdin);
gets(add);
cout<<"Enter Mobile Number:";
cin>>mbno;
fflush(stdin);

AGAIN:                   //GOTO STATEMENT

cout<<"Enter Pizza(ITEM) Code:";
fflush(stdin);
cin>>i_code2;  

f2.write((char*)&pizza,sizeof(pizza));    //storing The Data of Only Pizza Menu And That is also of last menu
  cout<<"Do You Want To Enter More:";
cin>>ch;
if(ch=='y'||ch=='Y')
goto AGAIN; // goto to again LABEL
f2.close();
gen_bill(mbno,bill_no);
getch();                 //its just like printing the bill after order;

       
}
void order::show_order()
{
system("Color 5F");
int x;
// f1.open("D:\\menu.txt",ios::in|ios::out|ios::app);
cout<<"Bill_No:"<<setw(10)<<"Name"<<setw(20)<<"Address"<<setw(20)<<"Mobile No"<<setw(20)<<"Pizza Code"<<"\n\n";
while(f2.read((char*)&pizza,sizeof(pizza)))
{
cout<<bill_no<<setw(20)<<name<<setw(20)<<add<<setw(15)<<mbno<<setw(20)<<i_code2<<"\n";
x=i_code2;
fflush(stdin);
//cout<<"\nItem_Code"<<setw(18)<<"Pizza Name"<<setw(25)<<"Price"<<"\n\n";
// cout<<i_code2<<setw(25)<<p_name<<setw(20)<<price<<"\n";


}
getch();

f2.close();

/* while(f1.read((char*)&pizza,sizeof(pizza)));
{
if(x==i_code)
{

cout<<"\nItem_Code"<<setw(18)<<"Pizza Name"<<setw(25)<<"Price"<<"\n\n";
cout<<i_code<<setw(25)<<p_name<<setw(20)<<price<<"\n";
cout<<"\n\n\n\n\n\n\n"<<setw(50)<<"Amount-->RS "<<total;
}
f1.close();


} */

}

void order::gen_bill(int a, int tempBillNo)
{
system("color 1A");
int i_bill;
float total=0;

system("cls");
cout<<setw(80)<<"_______________________________________\n";
cout<<setw(80)<<"|=====================================|\n";
cout<<setw(80)<<"|          LOVELY PIZZA PVT. LTD      |\n";
cout<<setw(80)<<"|                                     |\n";
cout<<setw(80)<<"|       Jalandhar-Phagwara Highway    |\n";
cout<<setw(80)<<"|             Chehru -Punjab          |\n";
cout<<setw(82)<<"|=====================================|\n\n\n";

cout<<"Customer Name:"<<name<<"\t\tBill No:"<<tempBillNo;
cout<<"\nAddress:"<<add;
cout<<"\nContact No:"<<mbno;
//f1.open("D:\\menu.txt",ios::in|ios::out|ios::app);
f2.open("D:\\order.txt",ios::in|ios::out|ios::app);
cout<<"\n===================================================================\n";
cout<<"\n===================================================================\n";
cout<<"\n\nItem_Code"<<setw(18)<<"Pizza Name"<<setw(25)<<"Price"<<"\n\n";
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(a==mbno)
{
i_bill=i_code2;

f1.open("D:\\menu.txt",ios::in|ios::out|ios::app);
while(f1.read((char*)&pizza,sizeof(pizza)))
{
if(i_bill==i_code)
{
cout<<i_code<<setw(25)<<p_name<<setw(20)<<price<<"\n";
total+=price;
break;
}

}
f1.close();
}
    }
    cout<<"\n\n"<<setw(40)<<"TOTAL COST FOR ORDER IS RS:"<<total<<"\n";
    cout<<setw(50)<<"THANK YOU! AND VISIT AGAIN:\n";
//f1.close();
f2.close();
}

void order::search()
{
  system("Color 2F");
 
long b;
  float total=0;

  Back: //goto function to move back and search again.....

  system("cls");
  found=0;
cout<<"Enter Mobile_No To Be Searched: \n"<<setw(10)<<"Enter 99 Any time When You Wish To go Back(MENU): ";
cin>>b;
f2.open("D:\\order.txt",ios::in|ios::out|ios::app);
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(b==mbno)
{
cout<<"\n\nCustomer Name:"<<name;
cout<<"\nAddress:"<<add;
cout<<"\nContact No:"<<mbno;
found=1;
break;
}
}
f2.close();
if(found==1)
{
cout<<"\n\nItem_Code"<<setw(18)<<"Pizza Name"<<setw(25)<<"Price"<<"\n\n";
f2.open("D:\\order.txt",ios::in|ios::out|ios::app);
// f2.seekp(0,ios::beg);
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(b==mbno)
{
temp=i_code2;

f1.open("D:\\menu.txt",ios::in|ios::out|ios::app);
while(f1.read((char*)&pizza,sizeof(pizza)))
{
if(temp==i_code)
{
cout<<i_code<<setw(25)<<p_name<<setw(20)<<price<<"\n";
total+=price;
break;
}

}
f1.close();
}
}
cout<<"\n\n"<<setw(20)<<"TOTAL COST FOR PIZZA IZZ RS:"<<total<<"\n";
}


if (found==0)
{
    if(b==99)
    goto MENU;
system("cls");
cout<<"File/Record Not Found!!\n Press any key to enter again.....";
getch();
goto Back;
}

MENU:
f1.close();
f2.close();
}


void order::del_rec()
{
system("color 7C");
searchAgain:             //GOTO STATEMENT 
found=0;
long long x;
char ch;

cout<<"Enter Mobile Number:"<<setw(10)<<"(ENTER 99 ANY TIME #TO #GO #BACK::)";
cin>>x;
f2.open("D://order.txt",ios::in|ios::out|ios::app);
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(x==mbno)
{
cout<<"\n\nCustomer Name:"<<name;
cout<<"\nAddress:"<<add;
cout<<"\nContact No:"<<mbno;
temp=i_code2;
found=1;
}
}
f2.close();
if (found==0)
{
    if(x==99)
    goto MENU;
system("cls");
cout<<"File/Record Not Found!!\n Press any key to enter again.....";
getch();
goto searchAgain;
}

if(found==1)
cout<<"\n\nItem_Code"<<setw(18)<<"Pizza Name"<<setw(25)<<"Price"<<"\n\n";
f1.open("D:\\menu.txt",ios::in|ios::out|ios::app);

while(f1.read((char*)&pizza,sizeof(pizza)))
{
if(temp==i_code)
{
cout<<i_code<<setw(25)<<p_name<<setw(20)<<price<<"\n";

}


}
     // MENU LOCAL GOTO Object;

f1.close();
MENU:  

f2.open("D://order.txt",ios::in);
f3.open("D://order1.txt",ios::in|ios::out|ios::app);
while(f2.read((char*)&pizza,sizeof(pizza)))
{
if(x==mbno)
continue;
f3.write((char*)&pizza,sizeof(pizza));
}
f2.close();
f3.close();
remove("D://order.txt");
rename("D://order1.txt","D://order.txt");






}

void menu::delPizzaMenu()
{
system("color 5F");
int tempIcode;
found=0;
f1.open("D://menu.txt",ios::in|ios::out|ios::app);
delPizzaMenu:
cout<<"Enter Pizza Code:";
cin>>tempIcode;
while(f1.read((char*)&pizza,sizeof(pizza)))
{
if(tempIcode==i_code)
{
cout<<i_code<<setw(25)<<p_name<<setw(20)<<price<<"\n";
found=1;
}
}
f1.close();
if(found!=1)
{
if(tempIcode==99)
goto delPizzaMenu1;
cout<<"Required Data Is Not Found!!!,\n   PRESS ANY KEY TO ENTER AGAIN(ENTER 99 To GO BACK):\n";
getch();
goto delPizzaMenu;
}


f1.open("D://menu.txt",ios::in);
f4.open("D://menu1.txt",ios::in|ios::out|ios::app);
delPizzaMenu1: // goto function
while(f1.read((char*)&pizza,sizeof(pizza)))
{
if(tempIcode==i_code)
continue;
f4.write((char*)&pizza,sizeof(pizza));
}
f1.close();
f4.close();
remove("D://menu.txt");
rename("D://menu1.txt","D://menu.txt");


}




main()
{
system("Color 6B");
char pass[256] = {0},c;
    char pass1[] = "mujtaba1@";
    int pos = 0,count=0;
    Sleep(300);
    cout<<setw(30)<<"               ============================================\n";
    Sleep(300);
    cout<<setw(45)<<"                           PIZZA MANAGEMENT SYSTEM\n";
    Sleep(300);
    cout<<setw(45)<<"                         CREATED BY- MOHAMMAD MUJTABA\n";
    Sleep(300);
    cout<<setw(45)<<"                               SECTION - K1613\n";
    Sleep(300);
    cout<<setw(45)<<"                                ROLL NO- B47\n";
    Sleep(300);
    cout<<setw(30)<<"               =============================================\n";
    Sleep(300);
    cout<<setw(30)<<"               =============================================\n";
    Sleep(300);
    cout<<setw(30)<<"                          LOGIN INTERFACE (AUTHORIZED)\n";
    Sleep(300);
    cout<<setw(30)<<"               =============================================\n\n";
    Sleep(300);
    login:  // GOTO FUNCTION
    
    cout<<"\nEnter Password (Max 3 attempts) : ";
    
    do {
        c = getch();

        if( isprint(c) ) 
        {
            pass[ pos++ ] = c;
            cout<<'*';
        }
        else if( c == 8 && pos )
        {
            pass[ pos-- ] = '\0';
            cout<<"\b\b";
            
        }
    } while( c != 13 );
    
    system("cls");
    cout<<"Please Wait System Is Verifing data";
    for(i=0;i<40;i++)
    {
    Sleep(59);
    cout<<"_";
}

    if( !strcmp(pass,pass1) )
        {
        system("cls");
        cout<<setw(40)<<"                  PLEASE WAIT WHILE PROGRAM IS LOADING>>\n";
            for(i=0;i<40;i++)
     {
cout<<"/\\";
Sleep(50);

            }
        }
    else
        {
  cout<<"\n Wrong Password!!!\n PRESS ANY KEY & TRY AGAIN";
  getch();
  count++;
  if(count==3)
  exit(42);
  else 
  goto login;
 }
pizza.home_page();
}

Saturday, 7 April 2018

2 SUM Maximum or Minimun Subarray program / implementation in C++ / C

#include<bits/stdc++.h>
using namespace std;

main()
{
int a[]={1,4,5,6,7,9,9,10};
int n=sizeof(a)/sizeof(a[0]);
sort(a,a+n);
int j=n-1,i=0,num;
cout<<"Enter Number To find Sum:";
cin>>num;
for(int k=0;k<n;k++)
{
if(a[i]+a[j]>num)
j--;
else
if(a[i]+a[j]<num)
i++;
else
{
cout<<"Founded:"<<num<<"At Index:"<<"["<<i<<","<<j<<"]";
break;
}
}
}

Wednesday, 29 November 2017

Alternate Node Deletion in Singly Linked List in C/C++ Implementation

#include<iostream>
using namespace std;

struct node
{
int info;
node *link;
};

void insertFirst(node **start,int num)
{
node *temp=new node;
temp->info=num;
temp->link=NULL;
*start=temp;
cout<<"First:\n";
}

void insertLast(node *start,int num)
{
node *temp=new node;
temp->info=num;
temp->link=NULL;
while(start->link!=NULL)
{
start=start->link;
}
start->link=temp;
}

void deleteAlternate(node *start)
{
node *currnext=start->link;
node *nexttonext=start->link->link;
node *curr=start;
while(curr!=NULL &&curr->link!=NULL && curr->link->link!=NULL)
{
nexttonext=curr->link->link;
delete(curr->link);
curr->link=nexttonext;
curr=curr->link;
}
}




void disp(node *start)
{
while(start!=NULL)
{
cout<<" "<<start->info;
start=start->link;
}
cout<<"\n";
}





main()
{
node *start=NULL;
insertFirst(&start,1);
insertLast(start,2);
insertLast(start,3);
insertLast(start,4);
insertLast(start,5);
        cout<<"Before Deleting Linked List\n:";
disp(start);
deleteAlternate(start);
        cout<<"After Deleting Alternate Node:\n";
disp(start);
}

Header Linked List - Implementation in C++/C

#include<bits/stdc++.h>

using namespace std;

struct node
{
int info;
node *link;
};
struct header
{
node *next;
int total=0;
};

void insertFirst(node **start,int data,header *head)
{
node *temp=new node;
temp->info=data;
temp->link=NULL;
*start=temp;
head->next=temp;
head->total+=1;
}
void insertLast(node *start,header *head,int data)
{
node *temp=new node;

while(start->link!=NULL)
{
start=start->link;
}
start->link=temp;
temp->link=NULL;
temp->info=data;
head->total+=1;
}

void display(node *start,header *head)
{
cout<<"Elements are:\n";
while(start!=NULL)
{
cout<<" "<<start->info;
start=start->link;
}
cout<<"\nTotal Number Of Elements Are:"<<head->total;
}

void deleteAlternate(node *start,header *head)
{
cout<<"\nIn Delete Function:\n";
node *nexttonext;
node *curr=start;
while(curr!=NULL&&curr->link!=NULL)
{


if(curr->link->info%2!=0)
{
nexttonext=curr->link->link;
delete(curr->link);
curr->link=nexttonext;
head->total-=1;
curr=curr->link;
}


}


}
main()
{
int i=0;
char ch='y';
node *start=NULL;
header *head =new header;
cout<<"First Element Entered:\n";
while(ch=='y'||ch=='Y')
{

if(i==0)
insertFirst(&start,i,head),i++;
else
insertLast(start,head,i),i++;

cout<<"Do You Want More Record:";
cin>>ch;
}
display(start,head);
deleteAlternate(start,head);
display(start,head);
}




Implementation of Quick Sort in C/C++

// Created By Mohd Mujtaba... Visit https://playwithcplus.blogspot.in fb-> //facebook.com/playwithcplus

#include<bits/stdc++.h>
using namespace std;

int part(int arr[],int low,int high)
{
int i=(low-1);
int pivot=arr[high];
for(int j=low;j<high;j++)
{
if(arr[j]<=pivot)
{
i++;
swap(arr[i],arr[j]);
}
}
swap(arr[i+1],arr[high]);
return(i+1);
}
void quicksort(int arr[],int low,int high)
{
if(low<high)
{
int pi=part(arr,low,high);
quicksort(arr,low,pi-1);
quicksort(arr,pi+1,high);
}
}
main()
{
int arr[] = {10, 7, 8, 9, 1, 5};
    int n = sizeof(arr)/sizeof(arr[0]);
    quicksort(arr, 0, n-1);
    printf("Sorted array:");
    for(int i=0;i<n;i++)
    cout<<" "<< arr[i];
}

Monday, 6 November 2017

Program to find K' th smallest number in Array In C,C++

#include<iostream>
using namespace std;

main()
{
int n,t,k;
cout<<"Enter No Of Testcases:";
cin>>t;
cout<<"Enter Number Of Elements:";
cin>>n
cout<<"Enter K'th Number To be finded:";
cin>>k;
int a[n],count=0,i,j,countb=0;
int b[n],p,q;
for(q=0;q<t;q++)
{
for(p=0;p<n;p++)
{
    cin>>a[p];
}

for(i=0;i<6;i++)
{
count=0;

int temp=a[i];
for(j=0;j<6;j++)
{
if(temp==a[j])
count++;

}
if(count==k)
{
b[i]=a[i];
countb++;
}
}
int small=b[0];
for(i=0;i<countb;i++)
{
if(small>b[i])
small=b[i];
}
cout<<"K'th Smallest Number Is:"<<small;

}

}


C program to Implement Priority Queue Menu Driven Program

/*Program of priority queue using linked list*/
#include<stdio.h>
#include<stdlib.h>

struct node
{
int priority;
int info;
struct node *link;
}*front=NULL;

void insert(int item, int item_priority);
int del();
void display();
int isEmpty();

main()
{
int choice,item,item_priority;
while(1)
{
printf("1.Insert\n");
printf("2.Delete\n");
printf("03.Display\n");
printf("4.Quit\n");
printf("Enter your choice : ");
scanf("%d", &choice);

switch(choice)
{
case 1:
printf("Input the item to be added in the queue : ");
scanf("%d",&item);
printf("Enter its priority : ");
scanf("%d",&item_priority);
insert(item, item_priority);
break;
case 2:
printf("Deleted item is %d\n",del());
break;
case 3:
display();
break;
case 4:
exit(1);
default :
printf("Wrong choice\n");
}/*End of switch*/
}/*End of while*/
}/*End of main()*/

void insert(int item,int item_priority)
{
struct node *tmp,*p;

tmp=(struct node *)malloc(sizeof(struct node));
if(tmp==NULL)
{
printf("Memory not available\n");
return;
}
tmp->info=item;
tmp->priority=item_priority;
/*Queue is empty or item to be added has priority more than first element*/
if( isEmpty() || item_priority < front->priority )
{
tmp->link=front;
front=tmp;
}
else
{
p = front;
while( p->link!=NULL && p->link->priority<=item_priority )
p=p->link;
tmp->link=p->link;
p->link=tmp;
}
}/*End of insert()*/

int del()
{
struct node *tmp;
int item;
if( isEmpty() )
{
printf("Queue Underflow\n");
exit(1);
}
else
{
tmp=front;
item=tmp->info;
front=front->link;
free(tmp);
}
return item;
}/*End of del()*/

int isEmpty()
{
if( front == NULL )
return 1;
else
return 0;

}/*End of isEmpty()*/

void display()
{
struct node *ptr;
ptr=front;
if( isEmpty() )
printf("Queue is empty\n");
else
{    printf("Queue is :\n");
printf("Priority       Item\n");
while(ptr!=NULL)
{
printf("%5d        %5d\n",ptr->priority,ptr->info);
ptr=ptr->link;
}
}
}/*End of display() */

C program to Implement Queue using Stacks in C++

/*
 * C Program to Implement Queues using Stacks
 */
#include <stdio.h>
#include <stdlib.h>

void push1(int);
void push2(int);
int pop1();
int pop2();
void enqueue();
void dequeue();
void display();
void create();

int st1[100], st2[100];
int top1 = -1, top2 = -1;
int count = 0;

void main()
{
    int ch;

    printf("\n1 - Enqueue element into queue");
    printf("\n2 - Dequeu element from queue");
    printf("\n3 - Display from queue");
    printf("\n4 - Exit");
    create();
    while (1)
    {
        printf("\nEnter choice");
        scanf("%d", &ch);
        switch (ch)
        {
        case 1:
            enqueue();
            break;
        case 2:
            dequeue();
            break;
        case 3:
            display();
            break;
        case 4:
            exit(0);
        default:
            printf("Wrong choice");
        }
    }
}

/*Function to create a queue*/
void create()
{
    top1 = top2 = -1;
}

/*Function to push the element on to the stack*/
void push1(int data)
{
    st1[++top1] = data;
}

/*Function to pop the element from the stack*/
int pop1()
{
    return(st1[top1--]);
}

/*Function to push an element on to stack*/
void push2(int data)
{
    st2[++top2] = data;
}

/*Function to pop an element from th stack*/

int pop2()
{
    return(st2[top2--]);
}

/*Function to add an element into the queue using stack*/
void enqueue()
{
    int data, i;

    printf("Enter data into queue");
    scanf("%d", &data);
    push1(data);
    count++;
}

/*Function to delete an element from the queue using stack*/

void dequeue()
{
    int i;

    for (i = 0;i <= count;i++)
    {
        push2(pop1());
    }
    pop2();
    count--;
    for (i = 0;i <= count;i++)
    {
        push1(pop2());
    }
}

/*Function to display the elements in the stack*/

void display()
{
    int i;

    for (i = 0;i <= top1;i++)
    {
        printf(" %d ", st1[i]);
    }
}

Sunday, 10 September 2017

SNAKE GAME SIMPLIFIED IN C++ [Easiest Way]


//SNAKE GAME CREATED BY MOHD MUJTABA
// Follow Me on Insta @mujtaba.aamir1
// Facebook @mujtaba.aamir1
#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
using namespace std;
bool gameover;
int x,y;
const int width=20,height=20;
 int score=0;
int fruitX,fruitY;
enum DIRECTION{STOP=0,UP,DOWN,LEFT,RIGHT};
DIRECTION dir;

void draw()
{
system("cls");
    int i=0;
for(i=0;i<width+2;i++)
cout<<"#";
cout<<endl;
for(int j=0;j<height;j++)
{
for(i=0;i<width+2;i++)
{
if(i==0)
cout<<"#";
if(i==x&&j==y)
cout<<"O";
else
if(fruitX==i&&fruitY==j)
cout<<"F";
else 
cout<<" ";

if(i==width-1)
cout<<"#";
if(x==fruitX&&y==fruitY)
        {
        score+=10;
    fruitX= rand()%width;
    fruitY= rand()% height;
        }  

}
cout<<endl;
}

for(int i=0;i<width+1;i++)
cout<<"#";
cout<<endl;
cout<<"SCORE="<<score;
}


void input()
{
if(_kbhit())  // _kbhit is to find Keyboard input
{
switch(_getch())
{
case 'a':
dir=LEFT;
break;
case 'd':
dir=RIGHT;
break;
case 's':
dir=DOWN;
break;
case 'w':
dir=UP;
break;
case 'x':
gameover=true;
default:
break;
}
}
}

void logic()
{
switch(dir)
{
case UP:
--y;
break;

case DOWN:
++y;
break;

case RIGHT:
++x;
break;

case LEFT:
--x;
break;

default:
break;
}
if(x>=width)
x=0;
else if(x<0)
x=width;
if(y>=height)
y=0;
else if(y<0)
y=height;

}
void start()
{
gameover=false;
x=width/2;
 y=height/2;
fruitX=rand()%width;
fruitY=rand()%height;
score=0;
}

main()
{

start();
while(!gameover)
{
Sleep(50); // This function is used to delay the output
draw();
input();
logic();
}
}//end of main()

Amazon1Ads