0% found this document useful (0 votes)
5 views12 pages

PSIPL Template Expt

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)
5 views12 pages

PSIPL Template Expt

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/ 12

Name Vatsal Panchal

UID no. 2024800084


Experiment No. 8

AIM:
Apply the concepts of structures/union to solve a given problem.

Program 1

PROBLEM A men’s sports club keeps elaborate computerized records of all its members.
STATEMENT : The records contain typical information such as age, address, etc. of each
person. But there is also information about whether a member is an active
playing member, about whether he is married, and so on; if he is married the
record contains information about his wife’s name, the no. of children and their
names. Write a program which demonstrates how such a system might be
implemented. Show how the names of the wives of all active playing members
might be printed.
PROGRAM:

RESULT:
Program 2
PROBLEM An airline reservation system maintains records for possible flights
STATEMENT : consisting of
STARTING POINT 3 character code
DESTINATION 3 character code
STARTING TIME integer on scale 0001 – 2400
ARRIVAL TIME integer on scale 0001 – 2400
SEATS positive integer in suitable range.
Your program is to read 20 such records followed by queries of the form
STARTING
POINT– DESTINATION, one to a line. For each query, find whether there
is a possible flight with a seat available; if so, reduce the number of seats by
one and print out the flight details (or an apology).

PROGRAM: #include <stdio.h>


#include <string.h>

#define MAX_FLIGHTS 20

int main()
{
struct Flight
{
char startingPoint[4];
char destination[4];
int startTime;
int arrivalTime;
int seats;
};

struct Flight flights[MAX_FLIGHTS];

printf("Enter 20 flight records:\n");


for (int i = 0; i < MAX_FLIGHTS; i++)
{
printf("Flight %d:\n", i + 1);
printf("Starting Point: ");
scanf("%3s", flights[i].startingPoint);
printf("Destination: ");
scanf("%3s", flights[i].destination);
printf("Starting Time (0001 - 2400): ");
scanf("%d", &flights[i].startTime);
printf("Arrival Time (0001 - 2400): ");
scanf("%d", &flights[i].arrivalTime);
printf("Seats available: ");
scanf("%d", &flights[i].seats);
printf("\n");
}

printf("Enter queries for flights (Starting Point -


Destination) in format 'XXX-XXX'.\n");
printf("To stop, enter 'END' as the starting point.\
n");

int queryCount = 0;
char queryStartingPoint[4], queryDestination[4];

while (1)
{
printf("\nQuery %d: ", queryCount + 1);
scanf("%3s-%3s", queryStartingPoint,
queryDestination);

if (strcmp(queryStartingPoint, "END") == 0)
{
break;
}

int flightFound = 0;
for (int i = 0; i < MAX_FLIGHTS; i++)
{
if (strcmp(flights[i].startingPoint,
queryStartingPoint) == 0 && strcmp(flights[i].destination,
queryDestination) == 0)
{
if (flights[i].seats > 0)
{
flights[i].seats--;

printf("\nFlight Found:\n");
printf("Starting Point: %3s\n",
flights[i].startingPoint);
printf("Destination: %3s\n",
flights[i].destination);
printf("Starting Time: %04d\n",
flights[i].startTime);
printf("Arrival Time: %04d\n",
flights[i].arrivalTime);
printf("Available Seats after booking:
%d\n", flights[i].seats);
}
else
{
printf("Sorry, no available seats for
this flight.\n");
}

flightFound = 1;
break;
}
}

if (flightFound == 0)
{
printf("Sorry, no flight found from %s to %s.\
n", queryStartingPoint, queryDestination);
}

queryCount++;
}

return 0;
}
RESULT:
Program 3
PROBLEM A league table consists of a set of N records each representing the
STATEMENT: performance of a team. A record contains team name, no. of games played,
no. of games won, no. of games drawn, no. of games lost, no. of goals scored
and no. of points awarded (2 for a win and 1 for a draw). Write a program
which inputs a positive integer N, N records of the form above, a positive
integer M, the results of M games in the form, team1 goals scored team2 goals
scored. Based on the results of these M games, the program should update
the records and display the updated records.
PROGRAM:

RESULT:

Program 4
PROBLEM
STATEMENT:
ALGORITHM:
FLOWCHART:

PROGRAM:

RESULT:

Program 5
PROBLEM
STATEMENT:
ALGORITHM:

FLOWCHART:
PROGRAM:

RESULT:

CONCLUSION:

You might also like