Click here to Skip to main content
16,019,764 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Develop Console Application, which provides following facilities to Railway officer.
Railway officer will be be able to add a new train and delete a train that is not booked.
Create a menu driven application with the following menus
1. Add Train: Used to as new train
2. Delete Train: Helps in deleting a train only if its not booked
3. Book Ticket: Gets the source and destination and checks if a train is available with the given
source and destination. Gives message if no train is available otherwise get the Noof Passengers
and books the ticket
4. View Train: Used to view all the trains with the given source and destination
5. View Booked Tickets: Used to view all the booked tickets
6. Edit Train details: Edit source and destination or edit name,source and destination of train.
Implement using polymorphism. Method name should be editTrain and return type should be 1
if edit is successful otherwise 0.
Following is the approach to solve the problem.
Create train class with the following properties
• Id
• Name
• Source
• Destination
Create ticket class with the following properties
• TicketNo
• NoOfPassengers
• TrainId
Create Reservation class with a list of train and a list of ticket and the following methods
1) AddTrain(ITrain train):int
Add a train to the train list in reservation class and return auto generated Id.
2) viewTrains(string source,string destination):List<ITrain>
Search trains by source and destination and return the list of the trains which match the given
criteria
3) searchTrain(string source,string destination):int
This method will check if the train is available according to the given source and destination. If
match is found it should return train Id otherwise the method should return 0.
4) BookTicket(int noOfPassengers,int trainId,out int totalPrice): int
It will get number of passengers and should create a new ticket object with the given detail. It
should calculate the total price for booking and display it on console. Assume that price will be
unique for each passenger (200 rs per head).Maintain unique ticket No for bookings.
The method is expected to return total price and ticket number
5) viewAllBookedTickets():List<ITicket>
Should display detail for all the tickets booked.No parameters expected and the method is
expected to return list of type ticket
6) deleteTrain(int trainId):int: Delete train only if there is no reservation for that train. Return 1 if
successful otherwise return 0.
Create interface IReservation,ITrain and ITicket and the classes Reservation,Train and Ticket
NOTE: Each train can hold a maximum of 200 passengers. Handle all possible exceptions


What I have tried:

i just begin and cover the basic fundamental of c#...i want to design this console application with following classes and interfaces which are mention in describe the problem section...please help me how to create this console application.
Posted
Updated 3-Aug-16 23:10pm
Comments
F-ES Sitecore 28-Jul-16 10:07am    
We're not here to do your homework for you.
Maciej Los 4-Aug-16 9:14am    
Not a question at all!!!
You should try anything before you ask a question, but you did nothing!

I have student History it will help you by using that you can convert that into your problem


using System;

//Write a C# program to keep records and perform statistical analysis for a class of 20 students. The information of each student contains ID, Name, Sex, quizzes Scores (2 quizzes per semester), mid-term score, final score, and total score.
//The program will prompt the user to choose the operation of records from a menu as shown below:

//========================================================

// MENU

//========================================================

//1. Add student records

// 2. Delete student records

// 3. Update student records

// 4. View all student records

// 5. Calculate an average of a selected student’s scores

// 6. Show student who gets the max total score

// 7. Show student who gets the min total score

// 8. Find student by ID

//9. Sort records by total scores

// Enter your choice:1

// Note: All students records are stored in an array of structures


namespace Student_History
{
class program
{
struct Student
{
public string StdNumber;
public string StdName;
public string sex;
public float Quizz1;
public float Quizz2;
public float Assigment;
public float Midterm;
public float Final;
public float Total;
};
static void Main(string[] args)
{

try
{
Student[] Std = new Student[20];
int itemcount = 0;

DisplayMenu();
int yourchoice;
string confirm;

do
{

Console.Write("Enter your choice(1-9):");

yourchoice = int.Parse(Console.ReadLine());


switch (yourchoice)
{

case 1: Add(Std, ref itemcount); break;
case 2: delete(Std, ref itemcount); break;
case 3: update(Std, itemcount); break;
case 4: viewall(Std, itemcount); break;
case 5: average(Std, itemcount); break;
case 6: showmax(Std, itemcount); break;
case 7: showmin(Std, itemcount); break;
case 8: find(Std, itemcount); break;
case 9: bubblesort(Std, itemcount); break;

default: Console.WriteLine("invalid"); break;

}

Console.Write("Press y or Y to continue:");

confirm = Console.ReadLine().ToString();

} while (confirm == "y" || confirm == "Y");

}
catch (FormatException f)
{

Console.WriteLine("Invalid input");
}
Console.ReadLine();
}

static void DisplayMenu()
{
Console.WriteLine("========================================= ");
Console.WriteLine(" MENU ");
Console.WriteLine("========================================= ");
Console.WriteLine(" 1.Add student records");
Console.WriteLine(" 2.Delete student records");
Console.WriteLine(" 3.Update student records");
Console.WriteLine(" 4.View all student records");
Console.WriteLine(" 5.Calculate an average of a selected student's scores");
Console.WriteLine(" 6.Show student who get the max total score");
Console.WriteLine(" 7.Show student who get the min total score");
Console.WriteLine(" 8.Find a student by ID");
Console.WriteLine(" 9.Sort students by TOTAL");
}
static void Add(Student[] Std, ref int itemcount)
{
Again:
Console.WriteLine();
Console.Write("Enter Student ID:");
Std[itemcount].StdNumber = Console.ReadLine().ToString();
if (Search(Std, Std[itemcount].StdNumber, itemcount) != -1)
{
Console.WriteLine("This ID already exists.");
goto Again;
}

Console.Write("Enter student's Name:");

Std[itemcount].StdName = Console.ReadLine().ToString();


Console.Write("Enter student's Sex(F or M):");
Std[itemcount].sex = Console.ReadLine().ToString();


Console.Write("Enter student's Quizz1 score:");
Std[itemcount].Quizz1 = float.Parse(Console.ReadLine());


Console.Write("Enter student's Quizz2 score:");
Std[itemcount].Quizz2 = float.Parse(Console.ReadLine());


Console.Write("Enter student's Assigment score:");
Std[itemcount].Assigment = float.Parse(Console.ReadLine());


Console.Write("Enter student's mid term score:");
Std[itemcount].Midterm = float.Parse(Console.ReadLine());

Console.Write("Enter student's final score:");
Std[itemcount].Final = float.Parse(Console.ReadLine());

Std[itemcount].Total = Std[itemcount].Quizz1 + Std[itemcount].Quizz2 + Std[itemcount].Assigment + Std[itemcount].Midterm + Std[itemcount].Final;


++itemcount;
}
static void delete(Student[] Std, ref int itemcount)
{
string id;
int index;
if (itemcount > 0)
{
Console.Write("Enter student's ID:");
id = Console.ReadLine();
index = Search(Std, id.ToString(), itemcount);

if ((index != -1) && (itemcount != 0))
{
if (index == (itemcount - 1))
{

clean(Std, index);
--itemcount;

Console.WriteLine("The record was deleted.");
}
else
{
for (int i = index; i < itemcount - 1; i++)
{
Std[i] = Std[i + 1];
clean(Std, itemcount);
--itemcount;
}

}

}
else Console.WriteLine("The record doesn't exist. Check the ID and try again.");


}
else Console.WriteLine("No record to delete");
}

static void update(Student[] Std, int itemcount)
{
string id;
int column_index;
Console.Write("Enter student's ID:");
id = Console.ReadLine();
Console.Write("Which field you want to update(1-7)?:");
column_index = int.Parse(Console.ReadLine());

int index = Search(Std, id.ToString(), itemcount);

if ((index != -1) && (itemcount != 0))
{
if (column_index == 1)
{
Console.Write("Enter student's Name:");

Std[index].StdName = Console.ReadLine().ToString();
}

else if (column_index == 2)
{
Console.Write("Enter student's Sex(F or M):");
Std[index].sex = Console.ReadLine().ToString();
}
else if (column_index == 3)
{
Console.Write("Enter student's quizz1 score:");
Std[index].Quizz1 = float.Parse(Console.ReadLine());
}
else if (column_index == 4)
{
Console.Write("Enter student's quizz2 score:");
Std[index].Quizz2 = float.Parse(Console.ReadLine());
}
else if (column_index == 5)
{
Console.Write("Enter student's assigment score:");
Std[index].Assigment = float.Parse(Console.ReadLine());
}
else if (column_index == 6)
{
Console.Write("Enter student's mid term score:");
Std[index].Midterm = float.Parse(Console.ReadLine());
}
else if (column_index == 7)
{
Console.Write("Enter student's final score:");
Std[index].Final = float.Parse(Console.ReadLine());
}
else Console.WriteLine("Invalid column index");
Std[index].Total = Std[index].Quizz1 + Std[index].Quizz2 + Std[index].Assigment + Std[index].Midterm + Std[index].Final;


}
else Console.WriteLine("The record deosn't exits.Check the ID and try again.");

}
static void viewall(Student[] Std, int itemcount)
{

int i = 0;

Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "0", "1", "2", "3", "4", "5", "6", "7", "8");
Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "ID", "NAME", "SEX", "Q1", "Q2", "As", "Mi", "Fi", "TOTAL");

Console.WriteLine("==================================================================");

while (i < itemcount)
{

if (Std[i].StdNumber != null)
{

Console.Write("{0,-5}{1,-20}{2,-5}", Std[i].StdNumber, Std[i].StdName, Std[i].sex);

Console.Write("{0,-5}{1,-5}{2,-5}", Std[i].Quizz1, Std[i].Quizz2, Std[i].Assigment);

Console.Write("{0,-5}{1,-5}{2,-5}", Std[i].Midterm, Std[i].Final, Std[i].Total);

Console.Write("\n");
}

i = i + 1;
}

}
static void average(Student[] Std, int itemcount)
{
string id;
float avg = 0;
Console.Write("Enter students'ID:");
id = Console.ReadLine();
int index = Search(Std, id.ToString(), itemcount);
if (index != -1 && itemcount > 0)
{
Std[index].Total = Std[index].Quizz1 + Std[index].Quizz2 + Std[index].Assigment + Std[index].Midterm + Std[index].Final;
avg = Std[index].Total / 5;
}

Console.WriteLine("The average score is {0}.", avg);
}
static void showmax(Student[] Std, int itemcount)
{
float max = Std[0].Total;
int index = 0;
Console.WriteLine(itemcount);
if (itemcount >= 2)
{

for (int j = 0; j < itemcount - 1; ++j)
if (max < Std[j + 1].Total)
{
max = Std[j + 1].Total;
index = j + 1;

}
}

else if (itemcount == 1)
{
index = 0;
max = Std[0].Total;
}


else Console.WriteLine("Not record found!");

if (index != -1) Console.WriteLine("The student with ID:{0} gets the highest score {1}.", Std[index].StdNumber, max);


}


static void showmin(Student[] Std, int itemcount)
{

float min = Std[0].Total;
int index = 0;
if (itemcount >= 2)
{
for (int j = 0; j < itemcount - 1; ++j)
if (min > Std[j + 1].Total)
{
min = Std[j + 1].Total;
index = j + 1;

}

}

else if (itemcount == 1)
{
index = 0;
min = Std[0].Total;
}
else Console.WriteLine("No record found!");

if (index != -1) Console.WriteLine("The student with ID:{0} gets the lowest score {1}.", Std[index].StdNumber, min);


}

static int Search(Student[] Std, string id, int itemcount)
{
int found = -1;
for (int i = 0; i < itemcount && found == -1; i++)
{

if (Std[i].StdNumber == id) found = i;

else found = -1;
}

return found;

}


static void clean(Student[] Std, int index)
{
Std[index].StdNumber = null;
Std[index].StdName = null;
Std[index].sex = null;
Std[index].Quizz1 = 0;
Std[index].Quizz2 = 0;
Std[index].Assigment = 0;
Std[index].Midterm = 0;
Std[index].Final = 0;
Std[index].Total = 0;
}



static void find(Student[] Std, int itemcount)
{
string id;
Console.Write("Enter student's ID:");
id = Console.ReadLine();

Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "0", "1", "2", "3", "4", "5", "6", "7", "8");
Console.WriteLine("{0,-5}{1,-20}{2,-5}{3,-5}{4,-5}{5,-5}{6,-5}{7,-5}{8,-5}", "ID", "NAME", "SEX", "Q1", "Q2", "As", "Mi", "Fi", "TOTAL");

Console.WriteLine("============================================================");
int index = Search(Std, id.ToString(), itemcount);
if (index != -1)
{
Console.Write("{0,-5}{1,-20}{2,-5}", Std[index].StdNumber, Std[index].StdName, Std[index].sex);

Console.Write("{0,-5}{1,-5}{2,-5}", Std[index].Quizz1, Std[index].Quizz2, Std[index].Assigment);

Console.Write("{0,-5}{1,-5}{2,-5}", Std[index].Midterm, Std[index].Final, Std[index].Total);
Console.WriteLine();

}
else Console.WriteLine("The record deosn't exits.");

}


static void bubblesort(Student[] dataset, int n)
{
int i, j;
for (i = 0; i < n; i++)
for (j = n - 1; j > i; j--)
if (dataset[j].Total < dataset[j - 1].Total)
{
Student temp = dataset[j];
dataset[j] = dataset[j - 1];
dataset[j - 1] = temp;
}
}
}
}
 
Share this answer
 
Comments
Richard MacCutchan 4-Aug-16 5:49am    
You do not help people to learn by doing their work for them.
tewodrosabebe 21-Apr-18 13:55pm    
write the program vb.net which displays you first name last name,your sex and your id declare first and last name globals of string type i need vb.netmy project
Richard MacCutchan 21-Apr-18 15:13pm    
Yes, I did it two years ago.
Did you write anything? Start writing and we will help you out as you hit a problem. Until then, start at MSDN[^]. The program only requires a few objects and this seems like a homework and we don't do homeworks so that you get to learn more yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900