Please solve this problem

I need help to solve this problem:

Assume you are asked to create a database for Train Station System, which contains:
Structure Ships { Long ID, String Departure_Date, String Arrival_City, Float Arrival_Date, float tonnage}
Structure Workers{ Long ID, String Name, Long Ship_ID}
Structure Ships_Schedule {Ships ship, Workers worker[10], Float SideWalk_number }
Draw a complete flowchart and Write a complete C++ programe to do the following:
- Takes an array of size 10 from Ships_Schedule structure.
- Write a menu for user that contains:
• Press 1 to fill data of database.
• Press 2 to output data in the database
• Press 3 to search of “Khalid Hassan” as a worker.
• Press 4 to search about worker by his ID. [User will enter ID to search].
• Press 5 to search about Ships which arrive “Italy” at Sunday 10 May.
• Press 6 to search about ships which leave the port at 10:00 p.m.
• Press 7 to search about ships which tonnage more than 1000 ton.
• Press 8 to search about ships by its ID [User will enter ID to search].
• Press 9 to search about Ship will leave from sidewalk number 12.
• Press 10 to exit.
- Use Do … While to restart menu.
Well for the options you could use a switch statement?

For 2, I think you could use for-loops and cout whilst calling on the structs
For 3, storing the array of names as strings, then using a for loop and if-else conditionals to find the right person.
For 4-10, I would do the same same again.
You did not post any code so I assume you have nothing written yet. Here is a start for you to build on.

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
#include <iostream>
using namespace std;

int main() {
    
 int i;
 
 
 // a do while loop
 do {
     
     cout << "Enter a number: ";
     cin >> i;
     
     //A switch statement but you need to add function calls for each case.
     switch(i) {
      case 1:
      cout << "You picked 1.";
      break;
      case 2:
      cout << "You picked 2.";
      break;
      case 3:
      cout << "You picked 3.";
      break;
      case 4:
      cout << "You picked 4.";
      break;
      case 5:
      cout << "You picked 5.";
      break;
      case 6:
      cout << "You picked 6.";
      break;
      case 7:
      cout << "You picked 7.";
      break;
      case 8:
      cout << "You picked 8.";
      break;
      case 9:
      cout << "You picked 9.";
      break;
      case 10:
      cout << "You picked 10.";
      break;
      default:
      cout << "Not a valid choice.";
     }
     
     cout << endl;
     
 } while (i != 10);
 
 
 return 0;
}
Hello hanysama,

DO NOT try to write the whole program at once. I would start with the menu. Get it to display on the screen the way that you want. then move on from there. Compile often and fix any errors as the come up.

Then I would work on the structs and any variables you may need.

After that the rest of the program comes easier.

Have you studied functions yet? Putting the menu in a function that returns a valid choice can be easier.

When it comes to the menu consider this:
1
2
3
4
5
6
7
8
9
int choice{};

std::cout << '\n' << std::string(12, ' ') << "Main Menu\n" << std::string(35, '-') << '\n';

std::cout <<
    "1.) To fill data of database.\n"
    "2.) To output data in the database.\n"
    "\nEnter Choice: ";
std::cin >> choice;

The "cout" statement makes it a little easier to read and visualize what the menu will look like on the screen. Try to use as few "endl"s as you can. In a large program it could actually run slower due to the overhead of the "endl" function. Using "\n"s should be all that yo need and save the "endl" for the last line if needed.

Something that you may not be aware of is a "cout" statement followed by a "cin". The "cin" will flush or empty the output buffer before it allows an input.

In line 8 leaving out any "\n"s or "endl" will put the input on the same line as the prompt.

Work on the menu and post your code when you have finished.

Andy
Thank you all.
I need some help to do function and array code in this problem.
Hello hanysama,

I need some help to do function and array code in this problem.

That is fine, but it is your program. Post what you have done and point out what you do not understand.

It is not up to others here to do your work for you. No one can help until it is seen what you are doing wrong.

I do have some questions. The first line says that this is dealing with a "Train Station System", but the structs lead me to believe that they deal with ocean vessels. Which became confusing when I started thinking about getting the input.

In the "Shops" structure the "Departure_Date" is a std::string, but the "Arrival_Date" is defined as a floating point number. Is there a reason for this or just someones attempt to confuse.

If you need to use a floating point number "double" is preferred over "float".

When you get to defining an object of "Ships_Schedule" this may also need to be an array to keep track of more than one train/ship.

Post what you have done so far , so the everyone can get an idea of what you have to work with.

Andy
Adding to Andy's advice:

Do the first two menu options first (read the data and write it out). Make sure these are working before doing the others. After all, if you have a bug in reading or displaying the data, the other options aren't going to work.

Are you supposed to read the data from a file? From the user? I will be tedious to read the data for 10 ships, each with 10 workers, from the user.

It says that the arrival date is a float. How are dates represented ?
thanks all,
another question please.
how to declare this array:
Structure Ships { Long ID, String Departure_Date, String Arrival_City, Float Arrival_Date, float tonnage}
it isna an array, its a structure. They look like this:

1
2
3
4
5
6
7
8
9
struct ships
{
   long ID;
   string Date;
   float Arrive;
};

ships s;
s.ID = 42;


structs and classes are used defined types that can lump several basic types together into a new type with all the fields. They can also do much more, but that is a starting point.

once you have that ^^ you can make an array of them:
ships sarray[1000]; //array of ships.
Last edited on
Topic archived. No new replies allowed.