RSS

Category Archives: Structures

STRUCTURE TO FIND THE LARGEST, SMALLEST AND AVERAGE SALARY OF 10 EMPLOYEES

/* THIS PROGRAM CREATES AN ARRAY OF STRUCTURES NAMED EMPLOYEE AND PRINTS
THE LARGEST, LOWEST AND AVERAGE SALARY OF 10 EMPLOYEES    */

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

struct employee{
char name[30];
long int salary;
};
employee e[10];

void main()
{
clrscr();
long int largest=0, smallest=0,sum=0;
float average=0.0;

cout<<“Enter the Data of the Employees\n\n\n”;

for(int i=0; i<10; i++)
{
cout<<“EMPLOYEE “<<i+1<<‘\n’;
cout<<“\nNAME:\t”;
gets(e[i].name);
cout<<“\nSALARY:\t”;
cin>>e[i].salary;
if(i==0)
{
smallest = largest = e[i].salary;
}
if(e[i].salary > largest)
{
largest = e[i].salary;
}
if(e[i].salary < smallest)
{
smallest = e[i].salary;
}
sum += e[i].salary;
clrscr();
}

average = sum/10;

cout<<“\nThe Largest Salary is:\t”<<largest;
cout<<“\nThe Smallest Salary is:\t”<<smallest;
cout<<“\nThe Average Salary is:\t”<<average;

getch();
}

 
Leave a comment

Posted by on June 2, 2015 in Structures

 

PROGRAM TO PERFORM OPERATIONS ON A COMPLEX NUMBER

//THIS PROGRAM PERFORMS OPERATIONS ON A COMPLEX NUMBER

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

struct cnum;

int addr(int, int);
int addi(int, int);
cnum subtract(cnum &,cnum &);
cnum multiply(cnum *, cnum *);

struct cnum {
int real;
int imag;
};

void main()
{
clrscr();
cnum num1,num2,num;
cout<<“Enter Real parts\n”;
cin>>num1.real>>num2.real;

cout<<“Enter imaginary parts\n”;
cin>>num1.imag>>num2.imag;

cout<<“\nComplex Numbers Before Operation\n”;

cout<<num1.real<<“+”<<num1.imag<<“i  and  “<<num2.real<<“+”<<num2.imag<<“i\n”;

sleep(2);
cout<<“Complex Number after Addition\t\t”;
num.real = addr(num1.real,num2.real);
num.imag = addi(num1.imag,num2.imag);
cout<<num.real<<“+”<<num.imag<<“i\n”;

sleep(1);
cout<<“Complex Number after Subtraction\t”;
num = subtract(num1, num2);
cout<<num.real<<“+(“<<num.imag<<“)i\n”;

sleep(1);
cout<<“Complex Number after Multiplication\t”;
num = multiply(&num1, &num2);
cout<<num.real<<“+(“<<num.imag<<“)i\n”;

cout<<“\nProgram Over.Press any key to Terminate\n”;
getch();
}

int addr(int real1, int real2)
{
return real1+real2;
}

int addi(int imag1, int imag2)
{
return imag1+imag2;
}

cnum subtract(cnum &num1, cnum &num2)
{
cnum val;
val.real = num1.real – num2.real;
val.imag = num1.imag – num2.imag;
return val;
}

cnum multiply(cnum *num1, cnum *num2)
{
cnum num;
num.real = num1->real*num2->real – num1->imag*num2->imag;
num.imag = num1->real*num2->imag + num1->imag*num2->real;
return num;
}

 
Leave a comment

Posted by on March 29, 2015 in Structures

 

STRUCTURE HAVING AN ARRAY OF EMPLOYEES

/* THIS PROGRAM STORES INFORMATION ABOUT AN EMPLOYEE */

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <stdio.h>
#include <dos.h>
#include <process.h>

void read();

void print(int);

struct addr {
int hno;
char area[40];
char city[30];
};

struct jodate {
int day;
int month;
int year;
};

struct emprec {
int empno;
char name[40];
addr empadd;
long int salary;
jodate jdate;
};
emprec emp[100];

void main()
{
clrscr();

main:  cout<<setw(45)<<“EMPLOYEE RECORDS\n”;
cout<<setw(45)<<”  ________________\n”;
cout<<“\n\n\n\n”<<setw(8)<<“CHOOSE AN OPERATION\n”;
cout<<“\n\n\n”<<setw(8)<<“1.READ DATA OF AN EMPLOYEE\n”;
cout<<“\n”<<setw(8)<<“2.PRINT EXISTING RECORDS\n”;
cout<<“\n\n”<<setw(8)<<“EXIT FROM THE PROGRAM (press ‘E’)\n\n”;

char choice;
int id;
cin>>choice;

switch(choice)
{
char ch1;

case ‘1’ : read();
cout<<“\n <- BACK TO MAIN MENU (press B)\n”;
cout<<“\n EXIT FROM THE PROGRAM (press ‘E’)\n\n”;
cin>>ch1;
switch(ch1)
{
case ‘B’ : clrscr();
goto main;
case ‘b’ : clrscr();
goto main;
case ‘E’ : cout<<“\n\nTERMINATING IN 3 SECONDS”;
sleep(3);
exit(0);
case ‘e’ : cout<<“\n\nTERMINATING IN 3 SECONDS”;
sleep(3);
exit(0);
default  : cout<<“\n\nINCORRECT CHOICE\n”;
cout<<“TERMINATING IN 3 SECONDS”;
sleep(3);
exit(0);
}
break;

case ‘2’ : clrscr();
cout<<setw(50)<<“PRINTING RECORDS\n\n”;
cout<<setw(8)<<“\n\n”;
rec:     cout<<setw(8)<<“\nENTER EMPLOYEE ID:\t”;
cin>>id;
clrscr();
print(id);
cout<<“\n\n\n\nPRINT ANOTHER RECORD (press ‘P’)\n”;
cout<<“\n <- BACK TO MAIN MENU (press B)\n”;
cout<<“\n EXIT FROM THE PROGRAM (press ‘E’)\n\n”;
cin>>ch1;

switch(ch1)
{

case ‘P’ : clrscr();
goto rec;
case ‘p’ : clrscr();
goto rec;
case ‘B’ : clrscr();
goto main;
case ‘b’ : clrscr();
goto main;
case ‘E’ : cout<<“\n\nTERMINATING IN 3 SECONDS”;
sleep(3);
exit(0);
case ‘e’ : cout<<“\n\nTERMINATING IN 3 SECONDS”;
sleep(3);
exit(0);
default  : cout<<“\n\nINCORRECT CHOICE\n”;
cout<<“TERMINATING IN 3 SECONDS”;
sleep(3);
exit(0);
}

case ‘E’ : cout<<“\nTERMINATING IN 4 SECONDS\n”;
sleep(4);
exit(0);

default  : cout<<“\n\nINCORRECT INPUT”;
cout<<“\nTERMINATING IN 3 SECONDS\n\n”;
sleep(3);
exit(0);
}
getch();
}

void read()
{
char wish;
int i=0;

clrscr();

do{
cout<<setw(45)<<“READING RECORDS\n”;
cout<<setw(47)<<“_______________\n\n\n”;
cout<<setw(8)<<“EMPLOYEE “<<i+1<<“\n\n”;
cout<<setw(8)<<“ENTER EMPLOYEE ID\t”;
cin>>emp[i].empno;
cout<<setw(8)<<“\nENTER YOUR NAME:\t”;
gets(emp[i].name);
cout<<setw(8)<<“\nENTER SALARY:\t\t”;
cin>>emp[i].salary;
cout<<setw(8)<<“\nENTER JOINING DATE \n”;
cout<<setw(12)<<“Date:\t\t”;
cin>>emp[i].jdate.day;
cout<<setw(12)<<“Month:\t\t”;
cin>>emp[i].jdate.month;
cout<<setw(12)<<“Year:\t\t”;
cin>>emp[i].jdate.year;
cout<<setw(8)<<“\nENTER ADDRESS\n”;
cout<<setw(12)<<“House no.:\t\t”;
cin>>emp[i].empadd.hno;
cout<<setw(12)<<“Area:\t\t”;
gets(emp[i].empadd.area);
cout<<setw(12)<<“City:\t\t”;
gets(emp[i].empadd.city);
cout<<setw(8)<<“\n\nDETAILS SUCCESSFULLY RECORDED.\n”;
cout<<setw(8)<<“CONTINUE READING (Y/N):\t”;
cin>>wish;
i++;
if(wish==’Y’||wish==’y’)
clrscr();
else if(wish==’N’||wish==’n’)
{
sleep(0.5);
return;
}
else
{
cout<<“\n\nINCORRECT INPUT\n\nTERMINATING IN 3 SECONDS\n”;
sleep(3);
exit(0);
}
}while(wish==’Y’||wish==’y’);
}

void print(int id)
{
clrscr();
cout<<setw(45)<<“EMPLOYEE DATA\n”;
cout<<setw(46)<<“_____________\n\n”;
int flag=0;
for(int i=0;i<50;i++)
{
if(id==emp[i].empno)
{
flag++;
cout<<“\n”<<setw(8)<<“NAME:\t\t”;
puts(emp[i].name);
cout<<setw(8)<<“JOINING DATE:\t”;
cout<<emp[i].jdate.day;
cout<<“\n”<<setw(14)<<“MONTH:\t”;
cout<<emp[i].jdate.month;
cout<<“\n”<<setw(14)<<“YEAR:\t”<<emp[i].jdate.year;
cout<<“\n”<<setw(8)<<“ADDRESS:\t”<<emp[i].empadd.hno<<“,”<<emp[i].empadd.area<<“,”<<emp[i].empadd.city;
cout<<“\n”<<setw(8)<<“SALARY:\t\t”<<emp[i].salary;
}
}
if(flag==0)
{
cout<<“\nNO SUCH EMPLOYEE EXISTS\n”;
}
}

 
Leave a comment

Posted by on March 2, 2015 in Structures

 

STRUCTURE TO RECORD THE DETAILS OF A FILM

//THIS PROGRAM RECORDS DETAILS ABOUT A FILM

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

struct film;

void read(film *);

struct film {
char *name;
float rating;
int income;
char *pdcr;
};
film film1,film2;

void main()
{
clrscr();

film film1={“11111″,1.1,11111,”111111”};

cout<<“DETAILS OF FILM 1 ARE\n\nNAME:\t”;
puts(film1.name);
cout<<“PRODUCER’S NAME\t:”;
puts(film1.pdcr);
cout<<“INCOME:\t”<<film1.income;
cout<<“\nRATING:\t”<<film1.rating;

cout<<“\n\nENTER DETAILS OF FILM 2\n”;
read(&film2);
getch();
}

void read(film *film1)
{

cout<<“Name\t”;
gets(film1->name);
cout<<“\nProducer\t”;
gets(film1->pdcr);
cout<<“\nRating\t”;
cin>>film1->rating;
cout<<“\nIncome\t”;
cin>>film1->income;

return;
}

 
Leave a comment

Posted by on March 2, 2015 in Pointers and Arrays, Structures

 

STRUCTURE TO READ THE DETAILS OF ALL PERSONS IN A FAMILY AND PRINT THE DETAILS OF ASKED MEMBER

/*THIS PROGRAM READS DETAILS OF ALL PERSONS IN A FAMILY AND PRINTS
DETAILS OF ASKED MEMBER */

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <dos.h>
#include <process.h>
#include <string.h>

struct add
{
int hno;
char area[30];
char sector;
char city[20];
};
struct details
{
char name[40];
int age;
add address;
int id;
char phone[10];
}member[20];

void read(void);
void print(char []);

int val=0;

void main()
{
clrscr();
char num[10];
read();
clrscr();
cout<<“\nEnter the Phone Number of Person whose Details you Want to view\n”;
cin>>num;
print(num);
cout<<“\nThanks!\n”;
getch();
}

void read(void)
{
char wish;
int i=0;
do{
cout<<“Person “<<i+1;
cout<<“\nEnter Name:\t\t”;
gets(member[i].name);
cout<<“Enter Age:\t\t”;
cin>>member[i].age;
if(member[i].age>=18)
{
cout<<“Enter Voter id\t\t”;
cin>>member[i].id;
}
cout<<“Enter Phone Number\t”;
gets(member[i].phone);
cout<<“Enter Address\n”;
cout<<“House No:\t\t”;
cin>>member[i].address.hno;
cout<<“Sector:\t\t\t”;
cin>>member[i].address.sector;
cout<<“Area:\t\t\t”;
gets(member[i].address.area);
cout<<“City:\t\t\t”;
gets(member[i].address.city);
cout<<“\nDetails Successfully Recorded.\nContinue Reading Details of Next Person (Y/N)?\n”;
cin>>wish;
i++;
val++;
}while(wish==’Y’||wish==’y’);

if(wish==’N’||wish==’n’)
{
cout<<“\nThanks For Registration\n”;
}
else
{
cout<<“\nINVALID INPUT\nTerminating…”;
delay(1000);
exit(0);
}
}

void print(char num[])
{
for(int i=0;i<val;i++)
{
if(strcmp(num,member[i].phone)==0)
{
cout<<“\nName:\t\t”;
puts(member[i].name);
cout<<“Age:\t\t”;
cout<<member[i].age;
if(member[i].age>=18)
{
cout<<“\nVoter id:\t”;
cout<<member[i].id;
}
cout<<“\nPhone Number\t”;
puts(member[i].phone);
cout<<“House No.:\t”;
cout<<member[i].address.hno;
cout<<“\nSector:\t\t”;
cout<<member[i].address.sector;
cout<<“\nArea:\t\t”;
puts(member[i].address.area);
cout<<“City:\t\t”;
puts(member[i].address.city);
return;
}
}
cout<<“\nNo Matches Found.\nTerminating..”;
delay(2000);
exit(0);
}

 
Leave a comment

Posted by on March 2, 2015 in Functions, Structures

 

STRUCTURE TO READ THE DATA OF AN EMPLOYEE AND INCREEMENT HIS/HER SALARY

//THIS PROGRAM READS THE DATA OF AN EMPLOYEE AND INCREEMENTS HIS/HER SALARY

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

struct emp
{
int id;
char name[30];
int sal;
}e1;

void increement(emp *);

void main()
{
clrscr();
cout<<“Enter details\nName:\t\t\t”;
gets(e1.name);
cout<<“Employee ID\t\t”;
cin>>e1.id;
cout<<“Enter Salary:\t\t”;
cin>>e1.sal;
cout<<“\nIncreementing the Salary\n\nThe New Salary is: \t”;
increement(&e1);
cout<<e1.sal;
getch();
}

void increement(emp *ptr)
{
ptr->sal=ptr->sal+5000;
return;
}

 
Leave a comment

Posted by on March 2, 2015 in Pointers and Arrays, Structures

 

STRUCTURE TO RECORD AND PRINT THE DETAILS OF A VOTER

//THIS PROGRAM PRINTS THE DETAILS OF A VOTER

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <dos.h>
#include <process.h>
#define size 3

struct add{
int hno;
char street[80];
char city[80];
};
struct dob{
int dd;
int mm;
int yyyy;
};
struct vote {
char name[40];
add address;
dob birth;
int id;
} person[size];
void main()
{
clrscr();
for(int i=0;i<size;i++)
{
cout<<“\nEnter details of Person “<<i+1<<“\n”;
cout<<“Enter Voter id:\t\t”;
cin>>person[i].id;
cout<<“Name:\t\t\t”;
gets(person[i].name);
cout<<“DOB (dd mm yyyy):\t”;
cin>>person[i].birth.dd>>person[i].birth.mm>>person[i].birth.yyyy;
cout<<“Address:\n\t1.House No.\t”;
cin>>person[i].address.hno;
cout<<“\t2.Street:\t”;
gets(person[i].address.street);
cout<<“\t3.City:\t\t”;
gets(person[i].address.city);
}
cout<<“”;
int val;
cout<<“\nViewing details..\nEnter your Voter id:\t”;
cin>>val;
for(i=0;i<size;i++)
{
if(val==person[i].id)
{
cout<<“\n\nDetails of Person are:\n\n”;
cout<<“\nName:\t\t\t”;
puts(person[i].name);
cout<<“Date of Birth:\t\t”;
cout<<person[i].birth.dd<<“/”<<person[i].birth.mm<<“/”<<person[i].birth.yyyy;
cout<<“\nAddress:\n\t1.House No.\t”;
cout<<person[i].address.hno;
cout<<“\n\t2.Street:\t”;
puts(person[i].address.street);
cout<<“\t3.City:\t\t”;
puts(person[i].address.city);
getch();
cout<<“\nThanks!”;
delay(1000);
exit(0);
}
}
cout<<“\nNo such Person Exists\nTerminating!”;
delay(2000);
exit(0);
}

 
Leave a comment

Posted by on March 2, 2015 in Structures