Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hey there! I'll be really thankful if you help me with this task...I'm translating it from my language so there might be mistakes but I hope you're going to understand what I'm talking about.I just need advice on how to start doing the task because It seems really complicatet and hard to do.

Create a program with functions for:
A\Inserting data for sea travels(up to 25 sea travels) into file and array from the keyboard: Maritime Station:- route , name of ship, name of captain, prices of the tickets for 1st and 2nd class, number of passengers into 1st and 2nd class, sum of the sold tickets - during a chosen month. Displaying of the array content on screen.
B\ Displaying data for the ship when you insert the name of the ship from the keyboard.
C\ Displaying data for the sea travel with biggest amount of sold tickets.
Main function with menu...Use global variables.

I'm not saying I need the whole task I just need the beginning and some advice...I think I may start in this way:
C++
#include <isotream>
#include <fstream.h>
#include <string>
using namespace std;
struct maritime_station {
	const int MAX_SIZE = 25;
	char route [];
	char shipname[];
	char captainname[];

but I don't know how to continue... :((((
Posted
Updated 14-Dec-14 3:00am
v2
Comments
Maciej Los 14-Dec-14 9:26am    
Did you learned how to use classes?

Write down in you own word what the task at hand is and then write it from top-down in pseudo code. Only then start to code.
E.g.
menu:
forever do
   display menu
   ask for selection
   stop if end selected
   do the selected action
end
The needed data structures:
C
class travel:
   field: route
   field: ship
   field: captain
   field: price_first_class
   field: price_second_class
   field: passengers_first_class
   field: passengers_second_class
   method: static read_from_file(file) returns new travel or null
   method: static read_from_keyboard() returns new travel or null
   method: display() to console
end

class maritime_station:
   field: travels (container for max 25 travel elements)
   method: reset()
   method: read_from_file(path)
   method: read_from_keyboard()
   method: add(travel)
   method: display() to console
   method: display_filtered(predicate) to console
end
Some implementations:
method maritime_station::read_from_file(path)
   file = open(path for read)
   forever do
       travel = travel::read_from_file(file)
       if travel equals null, then go to end loop
       add(travel)
   end loop
   close(file)
end

method maritime_station::read_from_keyboard()
   forever do
       travel = travel::read_from_keyboard()
       if travel equals null, then go to end loop
       add(travel)
   end loop
end

method maritime_station::display_filtered(predicate)
   foreach travel in travels do
      if predicate(travel) travel.display()
   end loop
end

method maritime_station::display()
   foreach travel in travels do
      travel.display()
   end loop
end


Cheers
Andi
 
Share this answer
 
v3
Hi,
This is a nice assignment. Just a quick advice - please think about using C++ classes in your implementation, for example to handle data groups like "Sea Travel" etc. The class "Sea Travel" can contain members being "route", "capitain name" and a "Sea Travel List" could hold all "Sea Travel" objects and allow to do operations on them like Add, Delete, Save ...

Kind regards,
 
Share this answer
 
Well, it should be pretty straightforward (and you have to do your own homework).
If you can, use C++ standard library containers (e.g. std::vector) and, please note, for holding string, std::string is a better choice than array of characters.
 
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