联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2018-09-11 01:40


Shapes

Overview

You are to write a program that responds to input from the user by displaying some basic geometric shapes in the terminal window. The input will specify the shape required and provide details of the properties of the shape.

Your program should be able to print four shapes:

A right-angled triangle. The example below shows a right-angled triangle of height 5 and border thickness 1.

Text

A square. The example below shows a square of height 6 and border thickness 2.


A rectangle. The example below shows a rectangle of height 7, width 10, and border thickness 3.



A triangular pyramid. The example below shows a triangular pyramid that is 2 levels high and is composed of smaller triangles of size 3.


The second example below shows a triangular pyramid that is 3 levels high and is composed of smaller triangles of size 2.


   

Specification

The program shall comply with the following specification:

1.The program shall be written in C and compiled with GCC using the C99 standard.

2.The program shall print to the terminal window simple geometric shapes from the set of {right-angled triangle, square, rectangle} using the single character # and a triangular pyramid using the characters (/ \ _).

3.The units of measure shall be terminal window rows (hereafter "rows") in the vertical direction and character spaces (hereafter "spaces") in the horizontal direction.

4.When the program is run it shall print a short welcome message:

SHAPES: The shape printer.

5.The program shall then display the following message prompting user input from the keyboard:

Text

Please select a shape from the following list:

- (t) right-angled triangle

- (s) square

- (r) rectangle

- (p) triangular pyramid

6.The program shall print the following upon an invalid menu selection:

Invalid input.

and then again print the message specified by clause 5.

7.The program shall request a height for the shape that shall be a minimum of 1 row for all shapes excluding the triangular pyramid which shall have a minimum of 2 rows:

What height should the shape be?

The program shall print:

Invalid input.

in response to any invalid input including but not limited to characters and out-of-range numbers and request the height again.

8.Invalid input shall include but not be limited to characters and numbers that are out-of-range for any particular user entry required.

9.The rectangle shall require an additional width parameter to be requested with a minimum of 1 character space:

What width should the rectangle be?

The program shall print

Invalid input.

in response to any invalid input and request the size again.

10.The triangular pyramid shall require an additional level parameter to be requested, with a minimum of 1 row of triangles:

How many levels should the triangular pyramid have?

The program shall print:

Invalid input.

for any invalid input and request the number of levels again.

11.For all shapes except the pyramid the program shall request a border thickness from the user:

What thickness should the border have?

This value shall have a minimum of 1 and no maximum. Any value greater than half of the the smallest size parameter shall result in a completely-filled shape. Any invalid size shall give:

Invalid input.

and request the level number again.

12.The program shall then print the specified shape.

13.The program shall return to the shape selection menu given in clause 5 with the additional option of:

- (q) quit from SHAPES.

If this option is chosen the program will exit with a return value of 0.

Execution

Your submission must include a Makefile. Your code will be compiled by executing the command make in the root directory of your submission. The executable that is created must be called shapes. It must be created in the root directory of your submission.

Edstem will call your program in a number of test cases. These test cases work by giving input lines (similar to typing input and pressing enter on the terminal) and checking the output of your program against a text file we supplied that matches the specification requirements. You will need to match every character on all of the lines for the program to pass. Feedback is visible on a subset of the test cases to let you know you match the format.

Libraries

You may use any function in the C99 standard library. You may not use external sources of code—whether they be libraries or applications code—regardless of licensing.

The following standard library functions are likely to be useful:

Header <stdio.h> has input/output functions: scanf(), putchar(), printf()

Header <assert.h> has the bug-catching macro assert()

Expectations

This is an individual assignment, not group work. Although you can consult others about the use of specific functions, the code that you submit must be solely your own work: The result of your thought process, design decisions, implementation and testing.

We expect you to follow good design practices, including the use of functions to reduce complexity and code repetition.

Robust parsing (look it up!) of user input using scanf() will not be exhaustively tested in this assignment as string handling has not yet been covered. Most marks related to user input will come from accepting valid input or rejecting input that is not valid because it contains, for example, characters or numbers that are out of range.

You will make completing the assignment significantly easier if you start work on it early and adopt an incremental approach to implementation and testing. In other words,

oDo not code the entire program and then submit it for testing. Instead, code a small subsection and test it, then incrementally extend this subsection and re-test.

oDo not submit your first code at 10pm on the night that the assignment is due and expect everything to work...

Elements of the project are intended to be challenging. The triangular pyramid can be seen as an extension to get full marks - but not required to pass and only makes up 10% of the entire assignment.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp