0% found this document useful (0 votes)
46 views18 pages

Practical List 2

The document contains 5 programming questions and their solutions in C++. Each question defines a structure to hold data (e.g. book, candidate, account), includes functions for input, output and other operations, and contains a main function that runs the program and allows the user to select different options like input, display, search etc. The questions cover concepts like arrays of structures, functions, structures, user input and output.

Uploaded by

KARTIK DUTT
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)
46 views18 pages

Practical List 2

The document contains 5 programming questions and their solutions in C++. Each question defines a structure to hold data (e.g. book, candidate, account), includes functions for input, output and other operations, and contains a main function that runs the program and allows the user to select different options like input, display, search etc. The questions cover concepts like arrays of structures, functions, structures, user input and output.

Uploaded by

KARTIK DUTT
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/ 18

Practical List 2

Q1.

/*

Program Number: 8

Developed by: Puroo Kumar Roy, Pushkal Srivastava, Rahul Meena

Batch Number: 8

Date: 12-June-2016

*/

#include<iostream.h>

#include<iomanip.h>

#include<string.h>

#include<conio.h>

#include<stdio.h>

struct BOOK

int Bno;

char Bname[20], Author[20];

float Price;

};

void enter (BOOK &b)

cout << "Enter book number: ";

cin >> b.Bno;

cout << "Enter Book name: ";

gets (b.Bname);
cout << "Enter name of the author: ";

cin >> b.Price;

void display (BOOK b)

cout << setw(4) << b.Bno

<< setw(20) << b.Bname

<< setw(20) << b.Author

<< setw(5) << b.Price << endl;

void searchBno ( BOOK b, int x, int &found )

if ( b.Bno == x )

display (b);

found++;

void searchBname ( BOOK b, char x[], int &found )

if ( strcmp (x,b.Bname) )

display (b);

found++;
}

void main()

int option, no = 0, bnx, fno = 0, fna = 0;

char ch, bna[20];

BOOK b[20];

clrscr();

cout << "Choose your option: " << endl

<< "\t1. Enter" << endl

<< "\t2. Display" << endl

<< "\t3. Search Book Number" << endl

<< "\t4. Search Book Name" << endl;

do{

cin >> option;

switch (option)

case 1: cout << "Enter number of books: ";

cin >> no;

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

enter (b[i]);

break;

case 2: for ( i = 0; i < no; i++ )

display (b[i]);

break;

case 3: cout << "Enter the number you want to search: ";

cin >> bnx;


for ( i = 0; i < no; i++ )

searchBno ( b[i], bnx, fno );

if (!fno)

cout << "Entry not found";

break;

case 4: cout << "Enter the name you want to search: ";

gets (bna);

for ( i = 0; i < no; i++ )

searchBname ( b[i], bna, fna );

if (!fna)

cout << "Entry not found";

break;

default: cout << "Wrong input";

break;

cout << "Try again (y/n)? ";

cin >> ch;

} while (ch!='n');

//Output-
Q2.

/*

Program Number: 9

Developed by: Puroo Kumar Roy, Pushkal Srivastava, Rahul Meena

Batch Number: 8

Date: 12-June-2016

*/

#include<iostream.h>

#include<iomanip.h>

#include<string.h>

#include<conio.h>

#include<stdio.h>
struct CANDIDATE

int Cno, Score;

char Cname[20];

};

void Enter (CANDIDATE &c)

cout << "Candidate Number: ";

cin >> c.Cno;

cout << "Candidate Name: ";

gets (c.Cname);

cout << "Candidate Score: ";

cin >> c.Score;

void Display (CANDIDATE c)

cout << setw(3) << c.Cno

<< setw(20) << c.Cname

<< setw(4) << c.Score << endl;

void main()

clrscr();

CANDIDATE c[20];
int opt, no;

char ch;

cout << "Choose your option:" << endl

<< "\t1. Enter" << endl

<< "\t2. Display" << endl

<< "\t3. Sort" << endl;

do {

cin >> opt;

switch (opt)

case 1: cout << "Enter the number of candidates: ";

cin >> no;

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

Enter (c[i]);

break;

case 2: for ( i = 0; i < no; i++ )

Display (c[i]);

break;

case 3: CANDIDATE temp;

for ( i = 0; i < no; i++ )

if ( c[i].Score > c[i+1].Score )

temp = c[i];

c[i] = c[i+1];

c[i+1] = temp;

for ( i = 0; i < no; i++ )

Display (c[i]);
break;

default: cout << "Invalid selection" << endl;

break;

cout << "Try again (y/n)? ";

cin >> ch;

} while ( ch != 'n' );

//Output-

Q3.

/*

Program Number: 10

Developed by: Puroo Kumar Roy, Pushkal Srivastava, Rahul Meena

Batch Number: 8

Date: 12-June-2016
*/

#include<iostream.h>

#include<iomanip.h>

#include<stdio.h>

#include<conio.h>

struct ACCOUNT

int Acno;

char Name[20];

float Balance;

};

void enter (ACCOUNT &a)

cout << "Account number: ";

cin >> a.Acno;

cout << "Account name: ";

gets (a.Name);

cout << "Account balance: ";

cin >> a.Balance;

void display (ACCOUNT a)

cout << setw(4) << a.Acno

<< setw(20) << a.Name


<< setw(8) << a.Balance << endl;

void main()

clrscr();

ACCOUNT a[20];

int opt, no;

char ch;

cout << "Enter Option: "

<< "\t1. Enter"

<< "\t2. Display"

<< "\t3. Display > 100000" << endl;

do {

cin >> opt;

switch (opt)

case 1: cout << "Enter number of accounts: ";

cin >> no;

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

enter (a[i]);

break;

case 2: for ( i = 0; i < no; i++ )

display (a[i]);

break;

case 3: for ( i = 0; i < no; i++ )

if ( a[i].Balance > 100000 )

display (a[i]);
break;

default: cout << "Invalid selection" << endl;

break;

cout << "Try again (y/n)? ";

cin >> ch;

} while ( ch != 'n' );

//Output-

Q4.

/*

Program Number: 11

Developed by: Puroo Kumar Roy, Pushkal Srivastava, Rahul Meena

Batch Number: 8

Date: 12-June-2016
*/

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

#include<stdio.h>

struct FLIGHT

int Flno;

char DepTime[20], ArrTime[20];

float Fare;

};

void enter (FLIGHT &f)

cout << "Flight Number: ";

cin >> f.Flno;

cout << "Departure Time: ";

gets (f.DepTime);

cout << "Arrival Time: ";

gets (f.ArrTime);

cout << "Fare: ";

cin >> f.Fare;

void display (FLIGHT f)

{
cout << setw(3) << f.Flno

<< setw(20) << f.DepTime

<< setw(20) << f.ArrTime

<< setw(6) << f.Fare << endl;

void main()

clrscr();

FLIGHT f[20], low;

int opt, no;

char ch;

cout << "Choose option: " << endl

<< "\t1. Enter" << endl

<< "\t2. Display" << endl

<< "\t3. Show flight woth lowest fare" << endl;

do {

cin >> opt;

switch (opt)

case 1: cout << "Enter number of flights: ";

cin >> no;

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

enter (f[i]);

break;

case 2: for ( i = 0; i < no; i++ )

display (f[i]);

break;
case 3: for ( i = 0; i < no-1; i++ )

if ( f[i].Fare > f[i+1].Fare )

low = f[i+1];

f[i+1] = f[i];

f[i] = low;

display (f[0]);

break;

default: cout << "Invalid Selection" << endl;

break;

cout << "Try again (y/n)? ";

cin >> ch;

} while ( ch != 'n' );

//Output-
Q5.

/*

Program Number: 12

Developed by: Puroo Kumar Roy, Pushkal Srivastava, Rahul Meena

Batch Number: 8

Date: 12-June-2016

*/

#include<iostream.h>

#include<iomanip.h>

#include<conio.h>

#include<stdio.h>

struct STUDENT
{

int Admno, date, month, year;

char Sname[20];

void DOB()

cout << "Enter DOB (Date Month Year): ";

cin >> date >> month >> year;

};

void enter (STUDENT &s)

cout << "Enter Admission Number: ";

cin >> s.Admno;

cout << "Enter Name: ";

gets (s.Sname);

s.DOB();

void display (STUDENT s)

cout << setw(4) << s.Admno

<< setw (20) << s.Sname

<< setw (15) << s.date << ' ' << s.month << ' ' << s.year

<< endl;

void main()
{

clrscr();

STUDENT s[20];

int opt, no;

char ch;

cout << "Select your option:" << endl

<< "\t1. Enter" << endl

<< "\t2. Display" << endl

<< "\t3. Display for 1 1 1990, 2 2 1990, 3 3 1990" << endl;

do {

cin >> opt;

switch (opt)

case 1: cout << "Enter number of students: ";

cin >> no;

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

enter (s[i]);

break;

case 2: for ( i = 0; i < no; i++ )

display (s[i]);

break;

case 3: for ( i = 0; i < no; i++ )

if ( s[i].year == 1990 )

if ( s[i].date == 1 )

if ( s[i].month == 1 )

display (s[i]);

else if ( s[i].date == 2 )
if ( s[i].month == 2 )

display (s[i]);

default: cout << "Invalid selection" << endl;

break;

cout << "Try again (y/n)? ";

cin >> ch;

} while ( ch != 'n' );

//Output-

You might also like