Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Saturday, 16 March 2019

Program of Trees in C++ language

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

struct node{
int data;
node *left=NULL;
node *right=NULL;
};

class tree{
private:
node *root=NULL;
public:
void insert(int value);
std
};

void tree::insert(int value){
node *temp = new node;
temp->data = value;
if(root == NULL){
root = temp;
cout<<"\n**Root Inserted**\n";
}else{
node *current = root; // holds the address of nodes from root
node *ptr = NULL; //temporary pointer which hold the address of left/right node which is null
while(current != NULL){
ptr = current; //assigning the address of current node
if(value > current->data){
current=current->right;
}else if(value< current->data){
current = current->left;
}else{
cout<<"\n***Data already exist***\n";
return;
}
} // while ends here
if(value < ptr->data){
ptr->left = temp;
cout<<"Data inserted at Left after "<<ptr->data<<endl;
}else{
ptr->right = temp;
cout<<"Data inserted at Right after "<<ptr->data<<endl;
}
} // outer else ends here
}
int main(){
tree t1;
char c;
do{
int data;
cout<<"\n=======New Data==============\n\n";
cout<<"Enter data : ";
cin>>data;
t1.insert(data);
cout<<"\nDo you want to run this program again?(y/n) : ";
cin>>c;
}while(c=='y'||c=='Y');
getch();
}

output:



Share:

Saturday, 18 February 2017

C++ program of entering employee data and showing its output

In this program we will enter the record of employee and shows its output if the user wants.
The Code is given below.


//Code Starts
#include<iostream>
#include<conio.h>

using namespace std;

struct addr
{
       char houseno[20];
       char street[30];
       char city[20];
       char state[20];
};
struct emp
{
       char empno[10];
       char name[20];
       char desig[20];
       addr address;
       float basic;
}worker;

int main()
{
          emp evar;

  cout<<"Employee No: ";
  gets(evar.empno);
  gets(evar.name);
  cout<<"Designation: ";
  gets(evar.desig);
  cout<<"House No: ";
  gets(evar.address.houseno);
  cout<<"Street: ";
  gets(evar.address.street);
  cout<<"City: ";
  gets(evar.address.city);
  cout<<"State: ";
  gets(evar.address.state);
  cout<<"Basic Pay: ";
  cin>>evar.basic;
    cout<<endl;

     char ch;
     cout<<"Want to see ? (y/n)...";
     cin>>ch;
     if(ch=='y' || ch=='Y')
          {
  cout<<"\nEmployee Data:\n";
  cout<<"Employee No: "<<evar.empno;
  cout<<"\nName: "<<evar.name;
  cout<<"\nDesignation: "<<evar.desig;
  cout<<"\nAddress: "<<evar.address.houseno<<", ";
  cout<<evar.address.street<<", ";
  cout<<evar.address.city<<", ";
  cout<<evar.address.state<<endl;
  cout<<"Basic Pay: "<<evar.basic;
  cout<<"\n";
          }

          getch();

}


//Code Ends



Share:

C++ program , entering and showing student record through structure and function

In this program we will learn how to enter and show record of student through functions and structure.
The code is given below.


//CodeStarts

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

using namespace std;

struct stu{
          char rol[15],dep[20],sub[30],inc[50];
};
void show(stu &s1);
void input(stu &s1);

int main()
{
          stu s1;
         
           input( s1);
          show (s1);
         
          getch();
         
}

void input(stu &s1)
{
          cout<<"Enter roll#"<<endl;
          cin>>s1.rol;
         
          cout<<"Enter department"<<endl;
          cin>>s1.dep;
         
          cout<<"Enter main subject"<<endl;
          cin>>s1.sub;
         
          cout<<"Enter class incharge"<<endl;
          cin>>s1.inc;
}

void show(stu &s1)
{
cout<<"=============OUTPUT========================"<<endl;

 cout<<s1.rol<<" has depatment "<<s1.dep<<" and studying "<<s1.sub<<" with Incharge "<<s1.inc;

}

//Code ends


Share:

C++ program of knowing date of birth using structure

In this program we will how to enter date using structure and knows the date of birth of someone


//Code starts
#include<iostream>
#include<conio.h>

using namespace std;

class date{

 private:
  int day,month,year;
 
  public:
   void setday();
   void setmonth();
   void setyear();
  
   int getday();
   int getmonth();
   int getyear();
  
   void display();
  
};

void date::setday()
{
 cout<<"Enter day ";
 cin>>day;
}

void date::setmonth()
{
 cout<<"Enter Month ";
 cin>>month;
}

void date::setyear()
{
 cout<<"Enter Year ";
 cin>>year;
}

int date::getday()
{
 return day;
}

int date::getmonth()
{
 return month;
}

int date::getyear()
{
 return year;
}


void date::display()
{

 cout<<day<<"-"<<month<<"-"<<year<<endl;

}

int main()
{
 date d1;

 d1.setday();

 d1.setmonth();

 d1.setyear();

 d1.display();


  if(d1.getday()==25&&d1.getmonth()==12)
 {
  int age;
 
  age=d1.getyear()-1876;
  cout<<"Today is Quaid_E_Azam's "<<age <<"th Birthday";
 }
 
 getch();
}

//code ends





Share:

C++ program of entering employee data through functions and structure

In this program we will learn how to enter employee data through functions using structure.
The code is given below.

//code starts
#include <iostream>
#include <conio.h>

using namespace std;

struct emp
{
int id,salary;
char name[20];
};

void input (emp &emp1);

void show (emp emp1);

int main()
{
emp emp1;

input (emp1);

show (emp1);

     getch();

}

void input (emp &emp1)
{
cout<<"Enter Employee ID : "<<endl;
cin>>emp1.id;

cout<<"Employee Name : "<<endl;
cin>>emp1.name;

cout<<"Enter Salary :"<<endl;
cin>>emp1.salary;
}

void show (emp emp1)
{

cout<<"ID: "<<emp1.id<<endl;

cout<<"Name: "<<emp1.name<<endl;

cout<<"Salary: "<<emp1.salary;
}
//code ends


Share:

C++ program of calling a structure in a function

In this program we will learn, how to call a structure inside a function and insert its values outside the main()..
The code is given below with screenshot.

//Code starts

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

using namespace std;

struct student{
int id;
char name[15];
};

void show (student s1);

int main()

{
student s1;

show (s1);

getch();

}

void show (student s1)
{
cout<<"Enter Student name"<<endl;
cin>>s1.name;

cout<<"Enter your Roll Number"<<endl;
cin>>s1.id;

cout<<"Name: "<<s1.name << endl;
cout<<"ID: "<<s1.id;
}
//Code ends



Share:

Sunday, 12 June 2016

C++ structure program of person

In this program we will create structure of person enter data in structure and also show the entered data.
The code is given below.

//Code Starts

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

using namespace std;

struct person
{
char name[15];
char age[2];
char father_name[20];
char adress[40];
char phone[11];
};

int main()
{
person p;
cout<<"Enter Name "<<endl;
cin>>p.name;
cout<<"Enter Father's Name "<<endl;
cin>>p.father_name;
cout<<"Enter Age "<<endl;
cin>>p.age;
cout<<"Enter Adress "<<endl;
cin>>p.adress;
cout<<"Enter Mobile Number "<<endl;
cin>>p.phone;
cout<<"Your Entered Data :"<<endl;
cout<<p.name<<endl;
cout<<p.age<<endl;
cout<<p.father_name<<endl;
cout<<p.adress<<endl;
cout<<p.phone<<endl;
getch();
}
//Code Ends

OUTPUT:





Share: