1. Command line / Menu
Estimated time: 2h home work, 3h scheduled lab
You need to understand basic language constructs and input, output with scanf(),
printf(), getchar(), putchar() etc.. Build a simple file. It is good if you can create a
simple function.
Assignment 1
Create the start of our program for show-jumping competition administration. Do a
command line and menu for the program. Your program should:
• Read a command from the user
• Depending on the command given execute different tasks
During the course of the labs you will add functionality to your menu. Thus you will
gain from a design that make addition and modification of the program simple. To
begin with your program will only recognize three commands that will:
• Print a list of the commands available (a menu)
• Print information about the program (program name, authors, copyright, year,
version)
• Exit the program
It is your choice how the menu should look and how advanced it should be. A
simple command line that reads the number of the menu item to select is sufficient.
(Although you may want to modify such solution later on when you learned more).
If you are a beginner, solve one problem at a time. Start with a program that just
print a menu and exit. Add code that asks for user input and print whatever the user
entered. Add more code so the program print different things depending on what
the user entered. At last, make the program repeat itself instead of exiting
immediately.
Assignment 2
Test your menu with as much and as weird input you can figure out. What happen if
you enter characters and not digits? What if the user of your program put lot of
blanks and/or newlines before or after the input? What happens if the user hit
CTRL-Z?
Fix your program so that it seems impossible to crash, hang or otherwise corrupt.
Page 1 of 11
C Programming C Laboratory instructions
2. Result recording
Estimated time: 4h home work, 6h scheduled lab
Topics
You need further input, output understanding. stringstreams can be useful. How to
format output. How to use the Time header file. Including, using and compiling
“own” code (the timer) that resides in separate file. It is good if you can create a
function with reference parameters. It is good if you can separate your code in
different files. Study the complete example program given.
What do the manipulators setprecision and fixed in iomanip do? How does getline ()
work? How can the separete character be ignored as inputing? You may also find
the interesting functions in string header file.
Assignment 1
Write a program that assist time-measurement and result recording during a
showjumping competition. (Horse and rider dashing round a track jumping
obstacles. Each combination horse and rider is called an equipage.) The
competition (of one equipage) goes as follow:
1. The equipage enters the track
2. The referee say “start at will”
3. The equipage passes the start line
4. The equipage possibly pulls down obstacles, or the horse refuse to jump
(disobedience). the rider may also fall off etc..
5. The equipage passes the goal line
6. The equipage exit the track
7. The referee tell the result of the ride, how fast the ride was (the track time), and
how many penalties the equipage received.
The program should measure the time between point 2. and 3. (the preparation
time), and between point 3. and 5. (the track time).
Between point 2. and 3. the rider has a certain preparation time. If it is exceeded the
exceeding time is added to the track time.
If the final track time (after adjustments) exceeds a set maximum track time, then
one penalty for each started exceeding second is added to the penalties.
After each equipage finish - if it finish (see assignment 2) - the program should print
the following to support the referee:
• The total number of penalties
• How many penalties that resulted from exceeding maximum track time
• The final track time
You can study an example run of the program below. The preparation time and
Page 2 of 11
C Programming C Laboratory instructions
maximum track time is common for all equipages and asked for once at the start of
the program.
Assignment 2
At point 4. the program should understand the codes ‘p’ for pulldown (4 penalties),
‘r’ for refusal (4 penalties first time, elimination second time), ‘d’ for “did not finish”
and any number should be interpreted as time to be substracted from the total track
time (due to some event causing the need for obstacle repair before the ride could
continue).
Guidelines
• Do one step at a time. Start with a program that only display the user instructions.
Add input handling so the user must press enter to continue. Then add timing
between the input events, and corresponding calculation and output. Finally, add
interpretation of any codes entered in step 4 (use a subroutine for this).
• You are supposed to reuse the Timer class provided, not implement your own.
• You do NOT have to save anything, printing the result to display for referee
support is enough.
• You do NOT need any advanced input management that immediately reacts to
keys, it is enough the program read an entire input line and process it after the
user press enter. In fact, the user should not be required to press more keys than
absolutely necessary (and if he does they should be ignored), in most cases just
pressing enter should do the trick.
Additional requirements
• All time-measures should be printed with two decimals in fixed point form, as in the
example below.
• Use a subroutine to calculate the penalties from the input line.
• Create a working execute file
Page 3 of 11
C Programming C Laboratory instructions
Example output
User input is given in bold here to separate it from program output. Also § represent
the places where the user pressed enter (new line).
Example<1> lab0§
Enter preparation time: 45.00§
Enter max time: 34.00§
!!! Start number 1.
<press enter at clearance to start>
[n=stop result recording]§
countdown from 45.00 started
<press enter at start line passage>§
preparation took 46.30 seconds
timing started at 1.30 seconds
<record penalties and press enter to stop timing>
[p=pulldown,r=refusal,d=dnf,(number)=paus time]
prp4.0§
timing stopped at 39.46 seconds
Total time 35.46 seconds (1.46 seconds above max)
Total penalties: 14 (2 due to time)
!!! Start number 2.
<press enter at clearance to start>
[n=stop result recording]§
countdown from 45.00 started
<press enter at start line passage>§
preparation took 16.21 seconds
timing started at 0.00 seconds
<record record penalties and press enter to stop timing>
Page 4 of 11
C Programming C Laboratory instructions
[p=pulldown,r=refusal,d=dnf,(number)=paus time]§
timing stopped at 33.49 seconds
Total time 33.49 seconds
Total penalties: 0
!!! Start number 3.
<press enter at clearance to start>
[n=stop result recording]n§
result recording done.
Page 5 of 11
C Programming C Laboratory instructions
3. Start list
Estimated time: 4h home work, 6h scheduled lab
You will need to understand struct, string and how to use a array and iterators. You
need to use functions and parameter passing to structure your program. It is good
to separate the code in different files. You may use class and member functions.
Assignment 1
When competing in show-jumping, and indeed in many sports, it is common to have
a predefined list of competitors defining the order in which to start. For each start
如何用C++编译赛马程序软件?
答案:1 悬赏:50 手机版
解决时间 2021-07-25 04:39
- 提问者网友:你独家记忆
- 2021-07-24 21:05
最佳答案
- 五星知识达人网友:duile
- 2021-07-24 21:15
你好哦。
有幸看到你的问题。
但是又很遗憾到现在还没有人回答你的问题。也可能你现在已经在别的地方找到了答案,那就得恭喜你啦。
可能是你问的问题有些专业了,没人会。或者别人没有遇到或者接触过你的问题,所以帮不了你。建议你去问题的相关论坛去求助,那里的人通常比较多,也比较热心,可能能快点帮你解决问题。
祝你好运~!
希望我的回答也能够帮到你!
谢谢
有幸看到你的问题。
但是又很遗憾到现在还没有人回答你的问题。也可能你现在已经在别的地方找到了答案,那就得恭喜你啦。
可能是你问的问题有些专业了,没人会。或者别人没有遇到或者接触过你的问题,所以帮不了你。建议你去问题的相关论坛去求助,那里的人通常比较多,也比较热心,可能能快点帮你解决问题。
祝你好运~!
希望我的回答也能够帮到你!
谢谢
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯