Monday, 24 October 2022

Fundamentals of Variables

  Keywords:







Variables:

 

Every variable must have:

💬Data type
💬Name 
💬Size
💬value

Variable declaration:


Variable declaration:

Codes:

Data type sizes:


#include<iostream>
using namespace std;
int main()
{
cout<<"\nMemory Size of Data Types\n";
cout<<"Size Of short:"<<sizeof(short)<<endl; cout<<"Size Of short int:"<<sizeof(short int)<<endl;
cout<<"Size Of int:"<<sizeof(int)<<endl;
cout<<"Size Of Long int"<<sizeof(long int)<<endl;
cout<<"Size Of Long"<<sizeof(long)<<endl; cout<<"Size Of long long:"<<sizeof(long long)<<endl; cout<<"Size Of float:"<<sizeof(float)<<endl;
cout<<"Size Of double"<<sizeof(double)<<endl; cout<<"Size Of long double"<<sizeof(long double)<<endl;
}


Variable decleration:


#include<iostream>
using namespace std;

int main()
{

int age;  //variable declaration
age =30;  //assignment operation on variable age

int marks = 100; // variable definition i.e variable created as well as initialized

cout<<"age:"<<age<<" marks:"<<marks<<endl;


//overwriting previous values of variables age and marks

age = 31;
marks=98;

cout<<"Displaying new values of age and marks"<<endl;
cout<<"age:"<<age<<" marks:"<<marks<<endl;

}












C++ Programming from Problem Analysis to problem design, Ds Malik - 6th Addition.pdf

 



Click here to download Book.

BOOK URL

https://drive.google.com/file/d/11pdFEqRTBD0gukYZuUNlULHyMTkWAvdw/view?usp=sharing

Friday, 14 October 2022

Singly linked list

 

Singly Link list :

Insert at begining, at end and at given location code in C++


#include<iostream>
using namespace std;


class node
{
private:
int data;
node *next;
node *head;
node *ptr;
node *tail;
public:
node();
void insert_at_beg();
void insert_at_end();
void inset_at_loc(int loc);
void input_func();
    void display();
 
};

node::node()
{
next=head=ptr=NULL;
}
void node::input_func()
{
ptr=new node;
cout<<"Enter your data :";
cin>>ptr->data;
}
void node::insert_at_beg()
{
input_func();
if(head==NULL)
{
head=ptr;
ptr->next=NULL;
}
else
{
ptr->next=head;
head=ptr;
}
}
void node::insert_at_end()
{
input_func();
if(head==NULL)
{
head=ptr;
ptr->next=NULL;
}
else
{
node *temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=ptr;
}
}
void node::inset_at_loc(int loc)
{
input_func();
if(loc<=0)
{
cout<<"You entered invailed location"<<endl;
}
if(loc==1)
{
if(head==NULL)
{
head=ptr;
ptr->next=NULL;
}
else
{
ptr->next=head;
head=ptr;
}
}
else
{
node *temp=head;
for(int i=1;i<loc-1;i++)
{
temp=temp->next;
}
if(temp->next!=NULL)
{
ptr->next=temp->next;
temp->next=ptr;
}
else
{
temp->next=ptr;
ptr->next=NULL;
}
}
}
void node::display()
{
node *temp=head;
while(temp!= NULL)
{
cout<<"Data is :"<<temp->data<<""<<endl;
temp=temp->next;
}
}



int main()
{
node n;
n.insert_at_beg();
n.insert_at_beg();
n.insert_at_end();
n.inset_at_loc(2);
n.display();
return 0;
}

Fiver Account

 Fiver Account: https://www.fiverr.com/s/bPlNbN