Code:
Description: Programme to show the use the concept of array to implement each
stand, where each stand has a capacity of twenty (20) patrons.
The arrays should reflect a state of either 0’s for empty seats,
or 1’s for occupied seats.
A method of iteration should be used to print the capacity AND
state of EACH stand, before accepting a user’s input.
The age, stand, and index should be accepted as inputs to the
program (it should be assumed that patrons have paid before their
information is collected and that the users will choose their
stand based on the capacity printed for each stand and the state
at an index).
A total should be outputted for EACH classification of patrons,
when ALL stands have reached their capacity as well as a total of
the overall amount collected by EACH stand, when ALL stands have
reached their capacity.
*/
#include<stdio.h>
#include<conio.h>
#define SIZE 20
//void dispmain (void);
void inputage (void);
void inputstand (void);
//void fullfunc(void);
void seatfunc (int[]);
//void initial(void);
void printStandStatus(int[]);
void dispStand(int[]);
void printStandCapacity(void);
void report (void);
int standA[SIZE], standB[SIZE], standC[SIZE];
int totalchild;
int totaladult;
int totalsc;
float sumchild, sumadult, sumsc, suma, sumb, sumc;
main()
{
int totalchild = 0, totaladult = 0, j,totalsc = 0, sumchild = 0, sumadult = 0, sumsc = 0, suma = 0, sumb = 0, sumc = 0;
int i;
for(i = 0; i<SIZE; i++)
{
standA[i] = 0;
standB[i] = 0;
standC[i] = 0;
}
for (j = 1; j<= 60; j++)
{
printf("\n\n\t\tWELCOME TO ALLGAMES STADIUM MANAGEMENT SYSTEM\n\n");
printf("\t ùÝ---------------------------------------------ùß\n");
printf("\t ¢x ¢x\n");
printf("\t ¢x S T A G E ¢x\n");
printf("\t ¢x ¢x\n");
printf("\t ùã---------------------------------------------ùå\n\n");
//printf(" Exit ¡ö ¡÷ Exit\n");
//printf("\n ¢x ¢x ùÝ----------------------------ùß ¢x ¢x\n\t ¢x");
/*for(i = 0; i <= 9; i++)
{
printf("%d¡U", standA[i]);
}
printf("\n Stand A ¢x¡ô¢x ¢x----------------------------¢x ¢x¡ô¢x \n\t ¢x");
for(i = 10;i <= 19; i++)
{
printf("%d¡U", standA[i]);
}
printf("\n ¢x ¢x ùã----------------------------ùå ¢x ¢x\n\t ");
printf("\n ¢x ¢x ùÝ----------------------------ùß ¢x ¢x\n\t ¢x");
for(i = 0; i <= 9; i++)
{
printf("%d¡U", standB[i]);
}
printf("\n Stand B ¢x¡ô¢x ¢x----------------------------¢x ¢x¡ô¢x \n\t ¢x");
for(i = 10;i <= 19; i++)
{
printf("%d¡U", standB[i]);
}
printf("\n ¢x ¢x ùã----------------------------ùå ¢x ¢x\n\t ");
printf("\n ¢x ¢x ùÝ----------------------------ùß ¢x ¢x\n\t ¢x");
for(i = 0; i <= 9; i++)
{
printf("%d¡U", standC[i]);
}
printf("\n Stand C ¢x¡ô¢x ¢x----------------------------¢x ¢x¡ô¢x \n\t ¢x");
for(i = 10;i <= 19; i++)
{
printf("%d¡U", standC[i]);
}
printf("\n ¢x ¢x ùã----------------------------ùå ¢x ¢x\n\n"); */
printStandCapacity();
printf("\nPlease press any key to continue...");
getch();
system("cls");
inputage();
}
report();
getch();
}
void inputage (void)
{
char stand;
int age;
float cost;
float childcost;
float adultcost;
float sccost;
childcost = 80.00;
adultcost = 120.00;
sccost = 60.00;
printf("Please enter the age of the customer:\n");
scanf("%d", &age);
fflush(stdin);/*Clears the buffer*/
if(age <= 0)
{
printf("\nThe age you have entered is not valid. Please try again.\n\n");
inputage();
}
else
if (age <= 12)
{
totalchild += 1;
sumchild += childcost;
cost = childcost;
printf("\nYou will be billed as a child.\n");
}
else
if (age > 12 && age <= 64)
{
totaladult += 1;
sumadult += adultcost;
cost = adultcost;
printf("\nYou will be billed as an adult.\n");
}
else
if (age > 64)
{
totalsc += 1;
sumsc += sccost;
cost = sccost;
printf("\nYou will be billed as a senior citizen.\n");
}
printf("\nPlease enter the customer's preferred stand (A, B or C) :\n");
scanf("%c",&stand);
fflush(stdin);
if (stand == 'A' || stand == 'a')
{
seatfunc(standA);
suma= suma + cost;
}
else if (stand == 'B'|| stand == 'b')
{
seatfunc(standB);
sumb = sumb + cost;
}
else if (stand == 'C'|| stand == 'c')
{
seatfunc(standC);
sumc = sumc + cost;
}
else
{
printf("\nYou did not follow instructions,\n and as a result will have to re-enter your information\n");
getch();
system("cls");
inputage();
}
}
void seatfunc(int A[])
{
int seatnum, pos;
printf("\nPlease enter your preferred seat:\n");
scanf("%d", &seatnum);
pos = seatnum - 1;
if (seatnum <= 0)
{
printf("\nInvalid seat entered.\n");
}
if (A[pos] == 1)
{
printf("\nThat seat is already occupied.");
printStandStatus(A);
getch();
}
if(A[pos] == 0)
{
printf("\nThat seat is available.");
getch();
A[pos] = 1;
system("cls");
}
}
void printStandStatus(int A[])
{
printf("\n\nAvailable seats: ");
int i;
for(i = 0; i < SIZE; i++)
{
if(A[i] == 0){
printf("#%d ", i + 1);
}
}
}
void dispStand(int A[])
{
int pos, i, free = 0, occupied = 0;
// Check the seats occupied and available in stand
for(pos = 0; pos < SIZE; pos++)
{
if(A[pos] == 0)
free++;
if(A[pos] == 1)
occupied++;
}
printf("\tSeats occupied| %d\tSeats available| %d", occupied, free);
free = occupied = 0;
// Display stand's seating.
printf("\nSeat #: ");
for (i = 0; i < SIZE; ++i)
{
printf(" %2d", i +1);
}
printf("\n");
printf("Occupied:");
for (i = 0; i < SIZE; ++i)
{
printf(" %2d", A[i]);
}
printf("\n\n");
}
void printStandCapacity()
{
printf("\n\n\nStand A:");
dispStand(standA);
printf("\n\n\nStand B:");
dispStand(standB);
printf("\n\n\nStand C:");
dispStand(standC);
}
void report ()
{
printf("\n\t\t ALL STANDS ARE NOW FULL");
printf("\n\nThe number of children in the stadium is: %d\n The amount of money brought in by them is:$ %.2f", totalchild, sumchild );
printf("\n\nThe number of adults in the stadium is: %d\n The amount of money brought in by them is:$ %.2f", totaladult, sumadult );
printf("\n\nThe number of senior citizens in the stadium is: %d\n The amount of money brought in by them is:$ %.2f", totalsc, sumsc );
printf("\n\n Total collected for STAND A :$ %.2f", suma);
printf("\n\n Total collected for STAND B :$ %.2f", sumb);
printf("\n\n Total collected for STAND C :$ %.2f", sumc);
}