0% found this document useful (0 votes)
31 views

Program 1

The document contains 5 C++ programs that demonstrate the use of structures. Each program defines a structure to store data such as book details, candidate details, account details, flight details, and student details. The programs implement functions to read, display, and search/sort the stored data. They utilize basic C++ features like structures, arrays, and functions to organize and manipulate the data.

Uploaded by

Kartik Puri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Program 1

The document contains 5 C++ programs that demonstrate the use of structures. Each program defines a structure to store data such as book details, candidate details, account details, flight details, and student details. The programs implement functions to read, display, and search/sort the stored data. They utilize basic C++ features like structures, arrays, and functions to organize and manipulate the data.

Uploaded by

Kartik Puri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Program 1

#include<iostream.h>

#include<conio.h>

struct BOOK

int bno;

char bname[20];

char author[20];

float price;

}book[20];

void read()

int n;

cout<<"Enter number of books you want to enter = ";

cin>>n;

for (int i=0;i<n;i++)

cout<<"Enter book number = ";

cin>>book[i].bno;

cout<<"Enter book name = ";

cin>>book[i].bname;

cout<<"Enter book author = ";

cin>>book[i].author;

cout<<"Enter book price = ";

cin>>book[i].price;

cout<<endl;

}
void display()

int n;

for (int i=0;i<n;i++)

cout<<"Book number = "<<book[i].bno<<endl;

cout<<"Book name = "<<book[i].bname<<endl;

cout<<"Book author = "<<book[i].author<<endl;

cout<<"Book price = "<<book[i].price<<endl<<endl<<endl;

void searchno()

int r,n;

cout<<" Enter book number to be search : ";

cin>>r;

int found=0;

for(int i=0;i<n && found==0;i++)

if(book[i].bno==r)

found=1;

if(found==1)

cout<<"Book number = "<<book[i].bno<<endl;

cout<<"Book name = "<<book[i].bname<<endl;

cout<<"Book author = "<<book[i].author<<endl;

cout<<"Book price = "<<book[i].price<<endl<<endl<<endl;

}
}

void searchname()

int n;

char r[20];

cout<<" Enter book name to be search : ";

cin>>r;

int found=0;

for(int i=0;i<n && found==0;i++)

if(book[i].bname[i]==r[i])

found=1;

if(found==1)

cout<<"Book number = "<<book[i].bno<<endl;

cout<<"Book name = "<<book[i].bname<<endl;

cout<<"Book author = "<<book[i].author<<endl;

cout<<"Book price = "<<book[i].price<<endl<<endl<<endl;

void main()

read();

display();

int choice;

cout<<" Menu "<<endl;

cout<<"1. search for book number"<<endl;

cout<<"2. search for book name"<<endl;


cout<<"enter choice";

cin>>choice;

switch(choice)

case 1:searchno();

break;

case 2:searchname();

break;

default:cout<<"wrong choice";

Program 2
#include<iostream.h>

struct CANDIDATE

int cno;

char cname[20];

int score;

}candidate[40];

void read()

int n;

cout<<"Enter number of candidates you want to enter = ";

cin>>n;

for (int i=0;i<n;i++)

cout<<"Enter candidate number = ";


cin>>candidate[i].cno;

cout<<"Enter candidate name = ";

cin>>candidate[i].cname;

cout<<"Enter candidate score = ";

cin>>candidate[i].score;

cout<<endl;

void display()

int n;

for (int i=0;i<n;i++)

cout<<"Candidate number = "<<candidate[i].cno<<endl;

cout<<"Candidate name = "<<candidate[i].cname<<endl;

cout<<"Candidate score = "<<candidate[i].score<<endl<<endl<<endl;

void sort()

int C;

for(int m=0;m<C-1;m++)

for(int g=0;g<C-m-1;g++)

if (candidate[g].score>candidate[g+1].score)

CANDIDATE t=candidate[g];

candidate[g]=candidate[g+1];

candidate[g+1]=t;
}

cout<<"Ascending order of sort : "<<endl;

for (int i=0;i<C;i++)

cout<<"Candidate number = "<<candidate[i].cno<<endl;

cout<<"Candidate name = "<<candidate[i].cname<<endl;

cout<<"Candidate score = "<<candidate[i].score<<endl<<endl<<endl;

void main()

read();

display();

sort();

Program 3
#include<iostream.h>

struct ACCOUNT

int acno;

char name[20];

float balance;

}account[40];
void read()

int n;

cout<<"Enter number of accounts you want to enter = ";

cin>>n;

for (int i=0;i<n;i++)

cout<<"Enter account number = ";

cin>>account[i].acno;

cout<<"Enter name = ";

cin>>account[i].name;

cout<<"Enter balance = ";

cin>>account[i].balance;

cout<<endl;

void display()

int n;

for (int i=0;i<n;i++)

cout<<"Account number = "<<account[i].acno<<endl;

cout<<"Name = "<<account[i].name<<endl;

cout<<"Account balance = "<<account[i].balance<<endl<<endl<<endl;

}
void bal()

int n;

cout<<"Account whose balance >100000 :-"<<endl<<endl;

for(int i=0;i<n;i++)

if(account[i].balance>100000)

cout<<"Account number = "<<account[i].acno<<endl;

cout<<"Name = "<<account[i].name<<endl;

cout<<"Account balance = "<<account[i].balance<<endl<<endl<<endl;

void main()

read();

display();

bal();

Program 4
#include<iostream.h>

struct FLIGHT

{
int flno;

char deptime[20];

float arrtime[20];

float fare;

}flight[20];

void read()

int n;

cout<<"Enter number of flights you want to enter = ";

cin>>n;

for (int i=0;i<n;i++)

cout<<"Enter flight number = ";

cin>>flight[i].flno;

cout<<"Enter departure time = ";

cin>>flight[i].deptime;

cout<<"Enter arrival time = ";

cin>>flight[i].arrtime[i];

cout<<"Enter fare = ";

cin>>flight[i].fare;

cout<<endl;

}
void display()

int k;

for (int i=0;i<k;i++)

cout<<"Flight number = "<<flight[i].flno<<endl;

cout<<"Departure time = "<<flight[i].deptime<<endl;

cout<<"Arrival time = "<<flight[i].arrtime[i]<<endl;

cout<<"Fare = "<<flight[i].fare<<endl<<endl<<endl;

void lowest()

int n;

int min=flight[n-1].fare;

for(int i=0;i<n;i++)

if(flight[i].fare<min)

min=flight[i].fare;

cout<<"Least fare flight details = "<<endl;

cout<<"Fare = "<<flight[i].fare<<endl;

cout<<"Flight number = "<<flight[i].flno<<endl;

cout<<"Departure time = "<<flight[i].deptime<<endl;


cout<<"Arrival time = "<<flight[i].arrtime[i]<<endl;

void main()

read();

display();

lowest();

Program 5
#include<iostream.h>

struct DATE

int day;

int month;

int year;

};

struct STUDENT

int admno;

char sname[20];

DATE dob;
}s[40];

void read()

int n;

cout<<"Enter number of students you want to enter = ";

cin>>n;

for (int i=0;i<n;i++)

cout<<"Enter students admission number = ";

cin>>s[i].admno;

cout<<"Enter student name = ";

cin>>s[i].sname;

cout<<"Enter student date of birth = ";

cin>>s[i].dob.day>>s[i].dob.month>>s[i].dob.year;

cout<<endl;

void display()

int n;

for (int i=0;i<n;i++)

cout<<"Student admission number = "<<s[i].admno<<endl;

cout<<"Student name = "<<s[i].sname<<endl;

cout<<"Student date of birth = "<<s[i].dob.day<<" / "<<s[i].dob.month<<" /


"<<s[i].dob.year<<endl<<endl<<endl;
}

void ds()

int n;

for (int i=0;i<n;i++)

if(s[i].dob.day==s[i].dob.month && s[i].dob.year==1990)

cout<<"Student admission number = "<<s[i].admno<<endl;

cout<<"Student name = "<<s[i].sname<<endl;

cout<<"Student date of birth = "<<s[i].dob.day<<" / "<<s[i].dob.month<<" /


"<<s[i].dob.year<<endl<<endl<<endl;

void main()

read();

display();

ds();

You might also like