帮助我完成课程。 C ++ [英] Help me with my coursework. C++

查看:61
本文介绍了帮助我完成课程。 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
end

The 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
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


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, 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.


这篇关于帮助我完成课程。 C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆