C++ Source Code For Link List Free Download

Implementation Of  Link List As Data Structure:

                                                           This is a simple C++ code which implements the most important Data Structure Link List .The code contains three files header file,cpp file and the main file which contains main function.You can download all the files by clicking the download button below or you can also copy paste the code.


This is header file.


#ifndef FILE_H_INCLUDED
#define FILE_H_INCLUDED


class node
{//start of class
    public:
    int data;
    node *next;
    node();//constructor

};//end of class

class linklist
{//start of class
    private:
    node *root;

    public:
    linklist();//constructor
    ~linklist();//destructor
    void insert_node(int );
    void print();
    bool search_node(int );
    void delete_node(int );
    void destroy_list();

};//end of class


#endif // FILE_H_INCLUDED



This is cpp file.



#include<iostream>
#include<windows.h>
#include"file.h"

using namespace std;

//constructor function
node::node()
{
    next=NULL;
}

//constructor function
linklist::linklist()
{
    root=NULL;
}

void linklist::insert_node(int item)
{//start of function

    node *new_node=new node;
    new_node->data=item;

    node *current=root;
    node *previous;

    while (current!=NULL && current->data<item)
    {//start of while
        previous=current;
        current=current->next;

    }//end of while

    new_node->next=current;
    if (current==root)
    root=new_node;
    else
    previous->next=new_node;



}//end of function


void linklist::print()
{
    node *iterator=root;

    while (iterator!=NULL)
    {//start of while
        cout<<iterator->data<<"--";
        iterator=iterator->next;
    }//end of while
    cout<<"NULL";
}


bool linklist::search_node(int key)
{
    node *searcher=root;

    while (searcher!=NULL)
    {
        if (searcher->data==key)
        return true;
        else
        searcher=searcher->next;
    }
 return false;
}


void linklist::delete_node(int key)
{


    if (root->data==key)
    {
        node *ptr=root;
        root=ptr->next;

        delete ptr;
    }

    else
    {
        node *previous;
        node *current=root;
        node *temp;

        if (current->next==NULL)
        current=NULL;

        while (current!=NULL)
        {


            if (current->data==key)
            {
                temp=current;
                previous->next=current->next;
                delete temp;
                break;
            }

            else
            {
                previous=current;
                current=current->next;
            }

        }
    }




}

void linklist::destroy_list()
{
    node *temp;


    while(root!=NULL)
    {
        temp=root;
        root=root->next;
        delete temp;
    }
}

//destructor funtion
linklist::~linklist()
{
    destroy_list();
}





This is main file.

//implementation of link list
//made by Syed Azeem Abbas

#include <iostream>
#include<windows.h>
#include"file.h"

using namespace std;

void load_menu(int );
int CheckKeyPressed(int );


int main()
{

    node obj1;
    linklist obj2;

    int counter=0;
    bool condition=true;


    load_menu(counter);


    while (condition==true)
    {//start while



        int a=CheckKeyPressed(0);

        if (a==40)
        {//start if
            if (counter<4)
            {//start if
                counter++;
                system("cls");
                load_menu(counter);
            }//end if
        }//end if

        else if (a==38)
        {//start else if
            if (counter>0)
            {//start if
                counter--;
                system("cls");
                load_menu(counter);
            }//end if
        }//end else if


        else if(a==13)
        {//start else if
          switch (counter)
          {//start of switch
              case 0:
              {
                    system("cls");
                    int item;
                    cout<<"Enter the data you want to insert:";
                    cin>>item;
                    obj2.insert_node(item);
                    cout<<"Data inserted:";
                    cout<<endl<<endl;
                    system("pause");
                    load_menu(counter);
                    break;
              }

              case 1:
              {
                system("cls");
                obj2.print();
                cout<<endl<<endl;
                system("pause");
                load_menu(counter);
                break;
              }

              case 2:
              {
                system("cls");
                int key;
                cout<<"Enter the key you want to find:";
                cin>>key;
                if (obj2.search_node(key)==true) cout<<"Key is found:";
                else                             cout<<"Key is not found";

                cout<<endl<<endl;
                system("pause");
                load_menu(counter);
                 break;
              }

              case 3:
              {
                system("cls");
                int key;
                cout<<"Enter the key you want to delete:";
                cin>>key;

                if (obj2.search_node(key)==true)
                {
                    obj2.delete_node(key);
                    cout<<"Key deleted:";
                    cout<<endl<<endl;

                }
                else
                cout<<"Key is not found";
                system("pause");
                load_menu(counter);
                break;
              }

              case 4:
              {
                  condition=false;
                  break;
              }

          }//end of switch
        }//end else if

    }//end while




    system("pause");
    return 0;
}








void load_menu(int counter)
{//start of function
    system("cls");

    cout<<"             SELECT THE OPTION FROM MENU BY PRESSING ENTER"<<endl<<endl<<endl;

    if (counter==0)
    {
    cout<<"                              ->ADD NODE"<<endl;
    cout<<"                              PRINT LINK LIST"<<endl;
    cout<<"                              SEARCH NODE"<<endl;
    cout<<"                              DELETE NODE"<<endl;
    cout<<"                              EXIT"<<endl;
    }

    else if (counter==1)
    {
    cout<<"                              ADD NODE"<<endl;
    cout<<"                              ->PRINT LINK LIST"<<endl;
    cout<<"                              SEARCH NODE"<<endl;
    cout<<"                              DELETE NODE"<<endl;
    cout<<"                              EXIT"<<endl;
    }

    else if (counter==2)
    {
    cout<<"                              ADD NODE"<<endl;
    cout<<"                              PRINT LINK LIST"<<endl;
    cout<<"                              ->SEARCH NODE"<<endl;
    cout<<"                              DELETE NODE"<<endl;
    cout<<"                              EXIT"<<endl;
    }


    else if (counter==3)
    {
    cout<<"                              ADD NODE"<<endl;
    cout<<"                              PRINT LINK LIST"<<endl;
    cout<<"                              SEARCH NODE"<<endl;
    cout<<"                              ->DELETE NODE"<<endl;
    cout<<"                              EXIT"<<endl;
    }

    else if (counter==4)
    {
    cout<<"                              ADD NODE"<<endl;
    cout<<"                              PRINT LINK LIST"<<endl;
    cout<<"                              SEARCH NODE"<<endl;
    cout<<"                              DELETE NODE"<<endl;
    cout<<"                              ->EXIT"<<endl;
    }

}//end of function



int CheckKeyPressed(int waitTime)
{
    HANDLE h= GetStdHandle(STD_INPUT_HANDLE);
    INPUT_RECORD r;
    DWORD w = 1;
    DWORD eventss;
    DWORD waitResult=0;
    int keypressed = false;
    int toReturn = 0;

    waitResult = WaitForSingleObject(h,waitTime);

    if (waitResult == WAIT_OBJECT_0)
    {
        /*FlushConsoleInputBuffer(h);..commented out as this takes to asynchronous mode on some systems*/
        keypressed = ReadConsoleInput(h,&r,1,&eventss);

        if (keypressed && r.EventType==KEY_EVENT && r.Event.KeyEvent.bKeyDown)
            toReturn = r.Event.KeyEvent.wVirtualKeyCode;
     /*this should make sure that checkKeyPressed is       not called twice for arrow keys*/
        if (toReturn == 224)
            toReturn = CheckKeyPressed(waitTime);


        FlushConsoleInputBuffer(h);
    }
    return toReturn;
}





DOWNLOAD THE WHOLE PROJECT:




Download YouTube Video Even It Is Blocked Through Online Converters


Even The YouTube Has Been Blocked But You Can Download It Using Online Converters In a Simple Way:

If the YouTube has been blocked even then you can open the YouTube using Proxy Servers(method described in post  How To Open Blocked Sites) and you can also download the video through the help of online YouTube converters websites.Some of the sites are mentioned in the block.Their are many websites available online through you can convert any video or YouTube video to different formats by simply giving the url of the video or uploading it through your computer or directly browsing YouTube.

Following are some links through which you can convert YouTube videos online and can download it on your system.


1.Online Media Converter (www.mediaconverter.org) 
                              Media Converter is one of the way through which you can convert  your file in to different formats like mp3,audio,mp4,mpeg4 and avi.To converte visit www.mediaconverter.org.

Online Media Converter
Enter the Link of the file or upload a file from a computer or browse Youtube.After that enter the videos in the queue you want to insert.Click the back button on up and after that click on"go to next step button".


After that select the format of file in which you want to convert it and click on "start conversion".Your videos will we converted and you can download on to your pc.


2.Online Video Converter (www.onlinevideoconverter.com)
                                      Online video converter is also one of the way through which you can convert any youtube video to any format and download it to your system or watch it.To converte visit the site www.onlineconverter.com.

online video converter
Select any option you want if you want to convert video from Youtube or any other site to mp3 or other audio select option 1,if you want to convert to mp4 or other video formats select option 2.If you want to convert from your pc select option 3.

online video converter
 Now if you want to convert it from YouTube enter the url of the video and click arrow button.After that select the video format you want to convert.After the video has been converted save it your pc.

FOUR ALTERNATIVES TO OPEN BLOCK SITES



OPEN BLOCK SITES THROUGH  PROXY SERVERS
What is a Proxy Server?  
A proxy server is a computer that offers a computer network service to allow clients to make indirect network connections to other network services. A client connects to the proxy server, then requests a connection, file, or other resource available on a different server. The proxy provides the resource either by connecting to the specified server or by serving it from a cache. In some cases, the proxy may alter the client's request or the server's response for various purposes.
 
These are the four proxy servers through which you can open any blocked site.Download any one of them and enjoy freedom for searching web pages.Also download GProxy Tool with it a link given below if you are using Mozilla FireFox.


1.Ultra SurfDownload
2.Gate Free                                               Download
3.GPassDownload
4.GTunnelDownload


If you are using Firefox than also download add-ons GProxy Tool Bar
 click here to download gproxy tool.

Download GTunnel Free Proxy Server



Open Blocked Sites Through GTunnel
GTunnel is a proxy software(similar to: Ultra Surf,GPass and Free Gate) used to open any blocked site.If any site is blocked in your region than you can easily open that site by using GTunnel.The very awesome feature of this software is that it is not an Operating System depended whether it is Windows7,Windows Xp or Windows Vista.GTunnel provides you internet freedom and privacy.Download it by clicking on download button below and enjoy your freedom in searching and browsing.


If you are using Firefox than download add-ons GProxy ToolBar.To download GProxy Tool                                          
click here to download gproxy tool.


GTunnel Proxy Server




How to Download  And Run
step1:Click the download button below .
step2:Save the file on your desired place.
step3:Open the folder where you have download the file,it is a zip file,extract the file by rigth clicking and selecting extract here.
step4:Open the extracted folder and click the .exe file.
step5:A small window will open,minimize that window .Now open the blocked site and enjoy your freedom.If you liked this post share it.



 

Download Free Gate Free Proxy Server



Open Blocked Sites Through Free Gate
Free Gate is a proxy software(similar to: Ultra Surf,GPass and GTunnel) ,used to open any blocked site.If any site is blocked in your region than you can easily open that site by using Free Gate.The very awesome feature of this software is that it is not an Operating System depended whether it is Windows7,Windows Xp or Windows Vista.Free Gate provides you internet freedom and privacy.Download it by clicking on download button below and enjoy your freedom in searching and browsing.


If you are using Firefox than download add-ons GProxy ToolBar.To download GProxy Tool                                           
click here to download gproxy tool. 



Free Gate Proxy Server




How to Download  And Run

step1:Click the download button below .
step2:Save the file on your desired place.
step3:Open the folder where you have download the file,it is a zip file,extract the file by rigth clicking and selecting extract here.
step4:Open the extracted folder and click the .exe file.
step5:A small window will open,minimize that window .Now open the blocked site and enjoy your freedom.If you liked this post share it.







Download GPass Free Proxy Server


Open Blocked Sites Through GPass
GPass is a proxy software(similar to: Ultra Surf,Free Gate and GTunnel),used to open any blocked site.If any site is blocked in your region than you can easily open that site by using GPass.The very awesome feature of this software is that it is not an Operating System depended whether it is Windows7,Windows Xp or Windows Vista.GPass provides you internet freedom and privacy.Download it by clicking on download button below and enjoy your freedom in searching and browsing.

If you are using Firefox than download add-ons GProxy ToolBar.To download GProxy Tool                                           
click here to download gproxy tool
 

GPass Proxy Server


How to Download  And Run

step1:Click the download button below .
step2:Save the file on your desired place.
step3:Open the folder where you have download the file,it is a zip file,extract the file by rigth clicking and selecting extract here.
step4:Open the extracted folder and click the .exe file.
step5:A small window will open,minimize that window .Now open the blocked site and enjoy your freedom.If you liked this post share it. 




HOW TO GENERATE RANDOM NUMBER IN C++


C++ CODE FOR HOW TO GENERATE A RANDOM NUMBER
This code is an example of how to generate a random number in C++  language using srand function which changes the number randomization time respect to time.Time is most random thing which is changing at every moment.

HAPPY CODING!



//random generation of numbers

#include<iostream>
#include<string>
#include<cstdlib>//library for random number genertion
#include<ctime>//library for srand function


using namespace std;


int main()
{
    srand(time(0));/*this will allow rand() to generate according to changing time*/
    int num;
    num=1+rand()%50;/*it will generate random number from 1 to 50*/
    cout<<"RANDOM NUMBER GENERATED IS:"<<num<<endl;

    system("pause");
    return 0;

}




C++ FUNCTION TO SET CURSOR ON THE CONSOLE



C++ CODE TO SET CURSOR ON THE CONSOLE
This is a code having function of place cursor,which place the cursor on the console according to coordinates.Forexample,you want to print any thing at position 10,10 you will call function PlaceCursor(10,10) and than print it.


HAPPY CODING!



#include<iostream>
#include<windows.h>

using namespace std;


//this is function for place cursor
void PlaceCursor(int x,int y)
{
    COORD c;
    c.X = x;
    c.Y = y;

    HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(h,c);
}

int main()
{
    PlaceCursor(5,5);//this is position of cursor at console

    cout<<"HELLO WORLD"<<endl;//hello world will be  //printed at 5,5

    system("pause");
    return 0;
}




DOWNLOAD C++ CODE FOR PASSWORD SHOWN AS STARS



INPUT PASSWORD IN THE FORM OF STARS CODE WRITTEN IN C++:
This is code written in the programming language C++ which ask the user to enter the password on the console and password is shown as stars on the screen.You can download this code by clicking the download button below or you can copy paste.


HAPPY CODING!


#include <iostream>
#include<string>
#include<windows.h>

using namespace std;

int CheckKeyPressed(int waitTime)
{
    HANDLE h= GetStdHandle(STD_INPUT_HANDLE);
    INPUT_RECORD r;
    DWORD w = 1;
    DWORD eventss;
    DWORD waitResult=0;
    int keypressed = false;
    int toReturn = 0;

    waitResult = WaitForSingleObject(h,waitTime);

    if (waitResult == WAIT_OBJECT_0)
    {
        //FlushConsoleInputBuffer(h);..commented out as this takes to asynchronous mode on some systems
        keypressed = ReadConsoleInput(h,&r,1,&eventss);

        if (keypressed && r.EventType==KEY_EVENT && r.Event.KeyEvent.bKeyDown)
            toReturn = r.Event.KeyEvent.wVirtualKeyCode;
        //this should make sure that checkKeyPressed is not called twice for arrow keys
        if (toReturn == 224)
            toReturn = CheckKeyPressed(waitTime);


        FlushConsoleInputBuffer(h);
    }
    return toReturn;
}


char return_char(int a)
{
    char ch;

         if (a==65) ch='a';
    else if (a==66) ch='b';
    else if (a==67) ch='c';
    else if (a==68) ch='d';
    else if (a==69) ch='e';
    else if (a==70) ch='f';
    else if (a==71) ch='g';
    else if (a==72) ch='h';
    else if (a==73) ch='i';
    else if (a==74) ch='j';
    else if (a==75) ch='k';
    else if (a==76) ch='l';
    else if (a==77) ch='m';
    else if (a==78) ch='n';
    else if (a==79) ch='o';
    else if (a==80) ch='p';
    else if (a==81) ch='q';
    else if (a==82) ch='r';
    else if (a==83) ch='s';
    else if (a==84) ch='t';
    else if (a==85) ch='u';
    else if (a==86) ch='v';
    else if (a==87) ch='w';
    else if (a==88) ch='x';
    else if (a==89) ch='y';
    else if (a==90) ch='z';

return ch;
}

int main()
{
    string password;
    bool condition=true;
    int i=0;


cout<<"Enter the password:";

  while (condition==true)
  {//start while
   char c;

  int a=CheckKeyPressed(0);

      if (a==13)
      condition=false;

    else if (a>=65 && a<=90)
      {
        c=return_char(a);
        password=password+c;
        cout<<"*";
        }

  }//end while

  cout<<endl<<endl<<"Password entered:"<<password;

    return 0;

}







  DOWNLOAD CODE WITH EXECUTABLE FILE:





DOWNLOAD THOMAS CALCULUS SOLUTION MANUAL 11th EDITION



DOWNLOAD FREE SOLUTION MANUAL OF THOMAS CALCULUS 11th EDITION:
This is the brief solution manual of THOMAS CALCULUS 11th EDITION in which all chapters exercise questions are solved.To download this book click the download button below and enjoy e-book.







How to Download 

step1:Click the download button below .
step2:A new tab will open wait for 5 seconds and clik on Skip Ad.
step3:Save the file on your desired place.
step4:Open the folder where you have download the file,it is a pdf  file.
step5:Open the pdf file and enjoy the e-book  and if you like this post and download share with others.











DOWNLOAD C++ CODE FOR STACK IMPLEMENTATION USING LINK LIST

STACK IMPLEMENTATION USING LINK LIST SOURCE CODE :  

For those who are studying data structures with respect to C++  this is a source code for stack implemented by the use of linklist.Download it by clicking the download button below or you can copy paste the code.

HAPPY CODING!!!

This is header file.

#ifndef LIST_H_INCLUDED
#define LIST_H_INCLUDED

class data
{//start of class
    private:
    int element;
    data *Next;

    public:
    data();//constructor
    void add_data(data *&ptr);
    void print_data(data *ptr);
    int calculate_sum(data *ptr);
};//end of class




class list
{//start of struct
   private:
   int id;
   int sum;
   data *root;
   list *previous;

   public:
   list();//constructor
   //~list();//destructor
   void push(list *&head);
   void pop(list *&head);
   void print_node(list *head);
   void print_by_id(list *head);
};//end of class



#endif // LIST_H_INCLUDED



This is .cpp file

#include<iostream>
#include<windows.h>
#include"list.h"

using namespace std;


data::data()
{//start of constructor
    Next=NUnbsp;      system("cls");
                obj1.pop(head);
                system("pause");
                break;
            }//end of case 2

            case 3:
            {//start of case 3
                system("cls");
                cout<<"stack position is:"<<endl<<endl;
                obj1.print_node(head);
                system("pause");
 &nb;   cout<<"Enter the data:";
                cin>>node->element;

                 if (ptr==NULL)
                {//start if
                   ptr=node;
                   ptr->Next=NULL;
                }//end if
                else
                {//star else
                    data *current=ptr;
                    while(current->Next!=NULL)
                    {//start of while
                       current=current->Next;
                    }//end of while
                    current->Next=node;
                    node->Next=NULL;
                }//end else
                break;

            }//end of case1

            case 2:
            {//start of case 2
                flag=false;
                break;
            }//end of case 2


        }//end of switch
    }//end of while
}//end of function

void data::print_data(data *ptr)
{//start of function
    data *temp=ptr;
    int i=1;
    while(temp!=NULL)
    {//start while
        cout<<"data element "<<i<<" is:"<<temp->element<<endl;
        temp=temp->Next;
        i++;

    }//end while
}//end of function

int data::calculate_sum(data *ptr)
{//start of function
    int total_sum=0;
        data *temp=ptr;
    while(temp!=NULL)
    {//start while
        total_sum=total_sum+(temp->element);
        temp=temp->Next;

    }//end while

    return total_sum;
}//end of function



list::list()
{//start of constructor
   root=NULL;
   previous=NULL;
}//end of constructor


void list::push(list *&head)
{//start of function
    list *node=new list;

    cout<<"Enter the id:";
    cin>>node->id;

    data obj2;
    obj2.add_data(node->root);

    node->sum=obj2.calculate_sum(node->root);

    if (head==NULL)
    {//start if
       head=node;
       head->previous=NULL;
    }//end if
    else
    {//star else
        list *current=head;
        head=node;
        node->previous=current;

    }//end else

}//end of function

void list::pop(list *&head)
{//start of function
     data obj2;

    cout<<"Top of the stack node is poped:"<<endl;
    cout<<"id is:"<<head->id<<endl;
    cout<<"sum is:"<<head->sum<<endl;
    obj2.print_data(head->root);


    list *temp=head;
    head=head->previous;
    delete temp;





}//end of function

void list::print_node(list *head)
{//start of function
    list *temp=head;
    data obj2;
    while(temp!=NULL)
    {//start while
        cout<<"id is:"<<temp->id<<endl;
        cout<<"sum is:"<<temp->sum<<endl;
        obj2.print_data(temp->root);
        cout<<endl;
        temp=temp->previous;

    }//end while

}//end of function

void list::print_by_id(list *head)
{//start of function
    list *temp=head;
    data obj2;

    int enter_id;
    cout<<"Enter the id:";
    cin>>enter_id;

    while(temp!=NULL)
    {//start while
        if (temp->id==enter_id)
        {//start if
            cout<<"id is:"<<temp->id<<endl;
            cout<<"sum is:"<<temp->sum<<endl;
            obj2.print_data(temp->root);
        }//end if
            cout<<endl;
            temp=temp->previous;
    }//end while
}//end of function





This is main.cpp file.

//link list implementation using stacks

#include<iostream>
#include<windows.h>
#include"list.h"

using namespace std;


int main()
{//start of main

    list *head=NULL;
    list obj1;
    bool condition=true;

    while(condition==true)
    {//start of while
        system("cls");
        cout<<"Enter 1 to push node"<<endl;
        cout<<"Enter 2 to pop node"<<endl;
        cout<<"Enter 3 to print all"<<endl;
        cout<<"Enter 4 to print by id"<<endl;
        cout<<"Enter 5 to exit"<<endl;
        int a;
        cin>>a;

        switch (a)
        {//start of switch
            case 1:
            {//start of case 1
                obj1.push(head);
                break;
            }//end of case 1

            case 2:
            {//start of case 2
                system("cls");
                obj1.pop(head);
                system("pause");
                break;
            }//end of case 2

            case 3:
            {//start of case 3
                system("cls");
                cout<<"stack position is:"<<endl<<endl;
                obj1.print_node(head);
                system("pause");
                break;
            }//end of case 3

            case 4:
            {//start of case 4
                  system("cls");
                obj1.print_by_id(head);
                system("pause");
                break;
            }//end of case 4

            case 5:
            {//start of case 5
                condition=false;
                break;
            }//end of case 5

        }//end of switch
    }//end of while

return 0;
}//end of main



  DOWNLOAD CODE WITH EXECUTABLE FILE:


C++ SOURCE CODE FOR KITE FREE DOWNLOAD

DOWNLOAD FREE SOURCE CODE FOR KITE IN C++:

This is code written in language C++ that prints kite on the console for the given size.The program ask the user to enter the size of the kite and then print the kite on the console.You can download the code by clicking the download button below or you can copy paste the code.

HAPPY CODING!!! 

 

#include <iostream>
#include<windows.h>

using namespace std;


int kite_1(int x,int i,int j,int size)
{
    if (x>j)
    return 0;

    else
    {

        if (x==i || x==j || x==size || i==1)
        cout<<"*";

        else
        cout<<" ";
        x++;
        return kite_1(x,i,j,size);

    }
}


int kite_2(int i,int j,int size,bool condition)
{

    if (i>j)
    return 0;



  else
  {
if (i==0)
  {
    i=i+2;
    j=j-2;
    condition=false;
  }

     int x=1;
     kite_1(x,i,j,size);
      cout<<endl;

if (condition==true)
    {//start if
      i--;
      j++;
    }

    else
    {
        i++;
        j--;
    }
      return kite_2 (i,j,size,condition);
  }
}




int main()
{
    int size;
    cout<<"Enter the size:";
    cin>>size;
int i=size;
int j=size;
bool condition=true;

kite_2(i,j,size,condition);

system("pause");
return 0;


}

DOWNLOAD CODE WITH EXECUTABLE FILE:



 

DOWNLOAD C++ SOURCE CODE FOR PYRAMID SOLITAIRE

 

C++ SOURCE CODE FOR BEGINNERS LEVEL GAME PYRAMID SOLITAIRE: 

This is Pyramid Solitaire beginners level source code written in C++.You can download it by clicking the download button.Or you can copy paste from here.

Happy Coding!

 

#include<iostream>
#include<cstdlib>
#include<string>
#include<Windows.h>
#include<ctime>
#include<iomanip>


using namespace std;



//this function will generate random number cards
int randomnumber()
{//start of random number function

    int randomnumber= 1+rand() % 13;

    if (randomnumber==1)
        randomnumber=65;
    else if (randomnumber==11)
    randomnumber=74;
    else if (randomnumber==12)
    randomnumber=81;
    else if (randomnumber==13)
        randomnumber=75;

    return randomnumber;
}//end of random number function


int timecounter()
{//start of time function
           time_t now = time(0);
 tm *ltm = localtime(&now);
    int timmer;


 timmer= 1 + ltm->tm_min ;

    return timmer;
}//end of time function



//this function will converte characters in to their game value
int characterarray(int number)
{
        if (number==65)
        number=1;
    else if (number==74)
        number=11;
    else if (number==81)
        number=12;
    else if (number==75)
        number=13;
    return number;
}


int drawboard(char array[8][24])
{//start of drawboard function
    cout<<"DRAW PILE:"<<endl<<endl;
    cout<<"     ";

    for(int h=0;h<=11;h++)
    {//start for
        cout<<"col"<<h<<" ";
    }//end for

cout<<endl;
    for (int i=0;i<=0;i++)
{//start for
    cout<<"row"<<i;
        for (int j=0;j<=11;j++)
    {//start for

         if (array[i][j]==65 || array[i][j]==74 || array[i][j]==81 || array[i][j]==75 || array[i][j]==46)
         cout<<setw(5)<<static_cast <char> (array[i][j]);
        else
        cout<<setw(5)<<static_cast <int> (array[i][j]);

    }//end for
        cout<<endl<<endl<<endl;
}//end for



    cout<<"     ";

    for(int h=12;h<=23;h++)
    {//start for
        cout<<"col"<<h<<" ";
    }//end for

cout<<endl;
    for (int i=0;i<=0;i++)
{//start for
    cout<<"row"<<i;
        for (int j=12;j<=23;j++)
    {//start for

         if (array[i][j]==65 || array[i][j]==74 || array[i][j]==81 || array[i][j]==75 || array[i][j]==46)
         cout<<setw(6)<<static_cast <char> (array[i][j]);
        else
        cout<<setw(6)<<static_cast <int> (array[i][j]);

    }//end for
        cout<<endl<<endl<<endl;
}//end for   
    return 0;
}//end of drawboard function




int cardsboard(char array[8][24],int score,int timeremaining)
{//start of board function
int cardcounter=0;

cout<<"CARDS:"<<setw(60)<<"score="<<score<<endl<<endl;
cout<<"       ";
    for(int h=0;h<=6;h++)
    {//start for
        cout<<"colm"<<h<<" ";
    }//end for
cout<<setw(25)<<"time remaining="<<timeremaining<<"min"<<endl;
     for (int i=1;i<=7;i++)
     {
    cout<<"row"<<i;
         for (int j=0;j<=cardcounter;j++)
         {

         if (array[i][j]==65 || array[i][j]==74 || array[i][j]==81 || array[i][j]==75 || array[i][j]==46)
         cout<<setw(6)<<static_cast <char> (array[i][j]);
        else
        cout<<setw(6)<<static_cast <int> (array[i][j]);
         }




     cout<<endl<<endl<<endl;
     cardcounter++;
     }


    return 0;
}//end of board function

//this function will input row number
int rowfunction()
{//start of row function
    int row;
    cout<<endl<<"enter row number:";
    cin>>row;

    return row;
}//end of row function


//this function will input column number
int columnfunction()
{//start of column function
    int column;
    cout<<endl<<"enter column number:";
    cin>>column;

    return column;
}//end of row function


//this function will check whether all cards are finished or not
bool checkfunction(char array[8][24])
{//start of check function
    int checkcounter=0;
    int checkadder=0;
    bool checkcondition=true;

        for (int i=1;i<=7;i++)
     {
         for (int j=0;j<=checkcounter;j++)
         {
         if (array[i][j]=='.')
             checkadder++;
         }

     checkcounter++;

     }
        if (checkadder==28)
        {
            checkcondition=false;
        }

    return checkcondition;
}//end of check function


//this function will update the score
int scorecounter(int score)
{//start of score counter
    score=score+5;

    return score;
}//end of score counter



int pyramidsolitaire()
{//start of  function
    srand(time(0));

    char array[8][24];
    int frequency[14];
    int counter=0;
    int number;
    int arraynumber;
    bool frequencycounter=true;
    char input;


//this  will initialize the frequency of cards
    for (int i=1;i<=13;i++)
    {//stat for
        frequency[i]=0;
    }//end for


//start of assigning random number to draw pile
for (int i=0;i<=0;i++)
{//start for
        for (int j=0;j<=23;j++)
    {//start for

            arraynumber=randomnumber();
            number=characterarray(arraynumber);
            frequency[number]++;
            if (frequency[number]>4)
            {
                if (j>0)
                {
                    j--;
               continue;
                }
            }
        array[i][j]=arraynumber;

    }//end for
}//end for

 //end of assigning random number to draw pile


//start of assigning random number to cards

    for (int i=1;i<=7;i++)
     {
         for (int j=0;j<=counter;j++)
         {


                     arraynumber=randomnumber();            
                         number=characterarray(arraynumber);
                         frequency[number]++;
                         if (frequency[number]>4)
                         {
                             if (j>0)
                             {
                                 j--;
                             continue;
                             }
                         }
             array[i][j]=arraynumber;

       
        }//end for
     counter++;

     }
    //end of assigning random number to cards

bool condition=true;
int rowcard1;
int columncard1;
int rowcard2;
int columncard2;
int numb1;
int numb2;
int sum;
int score=0;
int count;
int timediff;
int timeremaining;
int time=timecounter();
bool excel=false;

while(condition==true)
{//start of while
    if (condition==true)
    {//start if
     system("cls");//this will clear the screen

     count=timecounter();
     timediff=count-time;
     if (timediff>=5)
     {//start if
     system("cls");
     cout<<"\n\n\n\n\n\n\n"<<setw(25)<<"score="<<score;
     Sleep(1000);
     system("cls");
     condition=false;
     }//end if
     timeremaining=5-timediff;

    drawboard(array);//this function will print draw pile
    cardsboard(array,score,timeremaining);//this function will print cards



    cout<<"CARD1:"<<endl;
    rowcard1=rowfunction();
    columncard1=columnfunction();
    numb1=characterarray(array[rowcard1][columncard1]);
    sum=numb1;



    if (sum!=13)
    {//start if
    cout<<endl<<"CARD2:"<<endl;
    rowcard2=rowfunction();
    columncard2=columnfunction();
    numb2=characterarray(array[rowcard2][columncard2]);
    sum=sum+numb2;
    excel=true;
    }//end


    if (sum==13)
    {//start if
        if (rowcard1==0 || rowcard1==7)
        {//start if
        array[rowcard1][columncard1]='.';
        score=scorecounter(score);
        }//end if

        else if (array[rowcard1+1][columncard1]=='.')
        {//start if
            array[rowcard1][columncard1]='.';
            score=scorecounter(score);
        }//end if

        if (excel==true)
        {//start if
            if (rowcard1==0 || rowcard1==7)
            {//start if
                array[rowcard2][columncard2]='.';
                score=scorecounter(score);
            }//end if

            else if (array[rowcard1+1][columncard1]=='.')
            {//start if
                array[rowcard2][columncard2]='.';
                score=scorecounter(score);
            }//end if
        }//end if

    }//end if





//this condition will check whether all cards are finished
if (checkfunction(array)==false)
{//start if
     system("cls");
     cout<<"\n\n\n\n\n\n\n"<<setw(25)<<"score="<<score;
     cout<<"\n"<<setw(25)<<"YOU WIN";
      Sleep(1000);
     system("cls");
    condition=false;
}//end if



}//start if
}//end of while

    return 0;
}//end of  function




int main()
{//start of main function

    int enter;
    bool switchcondition=true;

cout<<"PYRAMID SOLITAIRE BY:\n1.AZEEM ABBAS<<endl<<endl<<endl;
    while(switchcondition==true)
    {//start while
   
        cout<<"ENTER 1 TO START OR 0 TO EXIT:" ;
        cin>>enter;
        switch (enter)
        {//start of switch
        case 1 :
            pyramidsolitaire();//this will start the game
            cout<<endl<<endl;
            break;

        case 0 :
            switchcondition=false;

            break;

        default :
            cout<<endl<<"YOU HAVE ENTERED WRONG INPUT"<<endl<<endl;
        }//end of switch
    }//end while

    system("pause");

    return 0;
}//end of main function

 

DOWNLOAD THE CODE WITH EXECUTABLE FILE: