-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailwayManagementSystem.cpp
More file actions
141 lines (139 loc) · 3.73 KB
/
RailwayManagementSystem.cpp
File metadata and controls
141 lines (139 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <stdio.h>
#include <string.h>
struct Profile
{
char sex;
char name[50];
int age, phno, passID;
float cost;
}record[10];
int profile(int i )
{
printf("\nPassenger %d :- \n", (i+1));
printf("name : %s\n", record[i].name);
printf("age and gender : %d %c\n", record[i].age, record[i].sex);
printf("phone number %d\n", record[i].phno);
printf("original cost of ticket : %f\n", record[i].cost);
return 0;
}
float Discount(int i){
if(record[i].age >= 60)
{
if(record[i].sex == 'M')
{ return (0.40 * record[i].cost);}
else
{return (0.50 * record[i].cost);}
}
else if(record[i].age <= 12)
{
if(record[i].age <= 5)
{return (record[i].cost);}
else
{return (0.50 * record[i].cost);}
}
else
{
return 0.00;
}
}
int Search()
{
int search, c = -1, i;
printf("Enter passenger ID number : \n");
scanf("%d", &search);
for(i=0;i<10;i++)
{
if(search == record[i].passID)
{ c=i;
break;
}
}
return c;
}
int E_ticket(int j)
{
printf("\t\t\t\tRAILWAY MANAGEMENT\n\t\t\t\t (Domain based project)\n");
printf("Passenger ID number : %d", record[j].passID);
printf("Name : %s\n", record[j].name);
printf("Age : %d\n", record[j].age);
printf("Gender : %c\n", record[j].sex);
printf("Final ticket cost : %f\n",(record[j].cost - Discount(j) ));
return 0;
}
int BalanceSheet()
{
int *ptr;
int i;
float total;
float *cptr;
printf("\n\n\t RAILWAY ACCOUNT BALANCE SHEET\n");
printf("\nSNo \tPASSENGER ID NUMBER \t TICKET COST \n\n");
for(i=0; i<10; i++)
{
ptr = &record[i].passID;
cptr = &record[i].cost - Discount(i);
total = total + *cptr;
printf ("%d. \t\t %d \t\t %f\n", (i+1) , *ptr, *cptr);
}
printf("\n\nTOTAL AMOUNT : %f\n", total);
}
int main(){
int i,j, ch;
for( i=0; i<10; i++)
{
printf("Passenger ID number%d : ", (i+1));
scanf("%d", &record[i].passID);
printf("Enter name%d: ", (i+1));
scanf("%s", record[i].name);
printf("Enter age%d and gender%d : \n",(i+1) ,(i+1));
scanf("%d %c", &record[i].age, &record[i].sex);
printf("enter phone number%d\n",(i+1));
scanf("%d", &record[i].phno);
printf("Enter original cost of ticket%d : \n", (i+1));
scanf("%f", &record[i].cost);
}
do
{
printf("\n\nENTER USER'S CHOICE : \n1. Passenger Profile \n2. Discount calculation. \n3.Search a Passenger ID number. \n4. e-ticket. \n5.Print Railway Balance Sheet \n6.Exit \n");
scanf("%d", &ch);
switch (ch)
{
case 1 :
j = Search();
if(i>=0)
i = profile(j);
else
printf("Passenger ID NUMBER not found.\n");
break;
case 2 :
i = Search();
if(i>=0)
printf("\nDiscount for Passenger %d = %f\n",i+1, Discount(i));
else
printf("Passenger ID NUMBER not found.\n");
break;
case 3 :
i= Search();
if(i == -1)
{printf("Passenger ID NUMBER not found.\n");}
else
{ printf("Passenger ID Number found at %d : %d\n", ++i, record[i].passID);}
break;
case 4 :
i = Search();
if(i>=0)
j = E_ticket(i);
else
printf("Passenger ID NUMBER not found.\n");
break;
case 5 :
i = BalanceSheet();
break;
case 6 :
printf("Thankyou");
break;
default : printf("Invalid Choice");
}
}while(ch < 6);
return 0;
}