帮助我完成课程。 C ++ [英] Help me with my coursework. C++
问题描述
创建一个程序,其功能为:
A \通过键盘将海上旅行(最多25次海上旅行)的数据插入文件和阵列:海事站: - 航线,船名,船长名称,第1和第2级车票价格,第1和第2级乘客数量第二等级,售出门票的总和 - 在选定的月份。在屏幕上显示数组内容。
B\当您从键盘插入船名时显示船舶数据。
C\显示数据售票最多的海上旅行。
带菜单的主要功能...使用全局变量。
我不是说我需要完成的任务我只需要开头和一些建议...我想我可以这样开始:
#include < isotream >
#include < fstream.h >
#include < 字符串 >
使用 命名空间标准;
struct maritime_station {
const int MAX_SIZE = 25 ;
char route [];
char shipname [];
char captainname [];
但我不知道如何继续...... :(((
用你自己的文字记下手头的任务是什么,然后用自上而下的伪代码写下来。然后才开始代码。
例如菜单:
永远做
显示菜单
要求选择
停止如果结束选择
执行选定的操作
end所需的数据结构:
class travel:
字段:route
字段:ship
字段:captain
字段:price_first_class
字段:price_second_class
字段:passengers_first_class
字段:passengers_second_class
方法: static read_from_file(file)返回 new travel 或 null
方法: static read_from_keyboard()返回 new travel 或 null
方法:display()到console
end
class maritime_station:
field:travels(container for max 25 travel elements)
方法:reset()
方法:read_from_file(path)
方法:read_from_keyboard()
方法:add(travel)
方法:display()到console
方法:display_filtered(谓词)到控制台
end一些实现:
方法maritime_station :: read_from_file(path)
file = open(读取路径)
永远执行
travel = travel :: read_from_file(file)
如果旅行等于null,然后转到结束循环
add(travel)
end loop
close(file)
end
method maritime_station :: read_from_keyboard()
永远做
trav el = travel :: read_from_keyboard()
如果travel等于null,则转到end循环
add(travel)
end loop
end
method maritime_station :: display_filtered(predicate)
foreach旅行中的旅行需要
如果谓词(旅行)travel.display()
结束循环
结束
方法maritime_station :: display()
foreach travel in travels do
travel.display()
end loop
end
干杯
Andi
这是一个不错的作业。快速建议 - 请考虑在您的实现中使用C ++类,例如处理Sea Travel等数据组。Sea Travel类可以包含成员route,capitain name和Sea旅行清单可以容纳所有海上旅行物品并允许对它们进行操作,例如添加,删除,保存...
亲切问候,
嗯,它应该非常简单(并且你必须做自己的功课)。
如果可以的话,使用C ++
标准库容器(例如std :: vector
),请注意,对于保存字符串,std :: string
是一个比字符数组更好的选择。
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:
#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... :((((
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 endThe needed data structures:
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 endSome 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
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,
Well, it should be pretty straightforward (and you have to do your own homework).
If you can, useC++
standard library containers (e.g.std::vector
) and, please note, for holding string,std::string
is a better choice than array of characters.
这篇关于帮助我完成课程。 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!