日韩精品一区二区三区高清_久久国产热这里只有精品8_天天做爽夜夜做爽_一本岛在免费一二三区

合肥生活安徽新聞合肥交通合肥房產生活服務合肥教育合肥招聘合肥旅游文化藝術合肥美食合肥地圖合肥社保合肥醫院企業服務合肥法律

CSCI1120代寫、代做C++設計程序
CSCI1120代寫、代做C++設計程序

時間:2024-10-02  來源:合肥網hfw.cc  作者:hfw.cc 我要糾錯



CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Assignment 2: Gumball Machines
Due: 23:59, Thu 3 Oct 2024 File name: gumball.cpp Full marks: 100
Introduction
The objective of this assignment is to let you practice control flow structures in C++. It also involves the use of variables, operators, expressions, and standard input/output to reinforce your learning in the course thus far. You are to write a program to print an ASCII character pattern resembling the drawing of a gumball vending machine, such as Figure 1 below.
     container
_____ /____\ // \\ // \\ // OOOOO\\ //OOOOOOO\\ \\OOOOOOO// \\OOOOOO// \\OOOOO// \\____// \_____/ |_|
| |_| |
𝑛 = side length of the hexagon gum
gum flap (chute door)
𝑛 = side length of the square
     stand || || |_ _ _ _ _|
Figure 1: A sample character pattern resembling a gumball machine This gumball machine character pattern is composed of two parts:
1. Container: A hexagonal shape in double dashed lines is used to represent the container holding the gumballs. Each gumball is denoted by a capital letter 'O'.
2. Stand: A square shape below the hexagon is used to represent the stand supporting the gumball container. A small square of unit length (always at the center of the 2nd line) inside this stand shape is used to represent the chute door, i.e., the opening where gumballs come out.
The whole pattern is formed from the set of characters in Table 1 below. Table 1: Characters for printing the ASCII art drawing
  Character
Name of the Character
  _ Underscore
| Pipe (Vertical bar)
\ Backslash
/ Forward slash
O Letter O (denoting a gum)
Space Copyright © 2024 CSE, CUHK
Page 1 of 8
            
CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Instead of hardcoding, you are required to use loops and conditionals to print the drawing whose size can be scaled up or down according to the user input (See Table 2 for examples).
User Input
There are two user inputs required at the program start.
1. Side length (𝑛): it is the side length of the hexagon (or the square). This input controls the number of underscores that form the outer edge of the hexagon.
2. Stock of gumballs (w**4;w**5;w**0;𝑐𝑘): the initial number of gumballs to load into the vending machine.
Due to the double dashed line design of the hexagon and the spaces involved, the maximum number of gumballs that can be put into the container, i.e., its capacity (𝑐), is limited and determined by the following formula (deduced from the sum formula of an arithmetic series):
𝑐 = 3𝑛! − 8𝑛 + 5 ... (1)
Input validation
1. If the side length (𝑛) is smaller than 3, there is not enough room to print the chute door. When 𝑛 is getting too big, the output may overrun your terminal width and look distorted due to line wrapping. So, let us assume its valid range is between 3 and 29. (Note: in case you still see line wrapping issues in this range, you may resize your terminal via its settings.)
2. The initial number gumballs (w**4;w**5;w**0;𝑐𝑘) to load into the machine must lie between ⌊𝑐/2⌋ (floor of the division) and 𝑐, inclusive.
If the user input falls outside the valid range, the program will terminate immediately with an error message. See the Sample Runs section.
Size Scaling
Table 2 shows some examples to explain how the container shape and its capacity (𝑐) scale with the side length (𝑛) input.
Note that for making the width and height of the hexagon (or square) look similar in the console, we put a single space between every two underscores or two letter O’s in a horizontal line. For better visualization of the spaces required to produce the output, we used the symbol ␣ to denote a space character.
Machine Operations
Besides printing the gumball machine, the program will also prompt the user to enter a quantity of gumballs to buy. When the user enters a valid value (between 1 and w**4;w**5;w**0;𝑐𝑘), the quantity will be deducted from the stock and there will be fewer O’s shown in the next printout of the gumball machine. The program keeps repeating these operations until running out of stock.
 Copyright © 2024 CSE, CUHK Page 2 of 8

CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Table 2: Sample output versus side length (𝑛) 𝒏3456
𝒄8 21 4**5
         ␣␣␣␣_␣_␣_ ␣␣/␣␣_␣_␣␣\ ␣/␣/␣O␣O␣\␣\ /␣/␣O␣O␣O␣\␣\ \␣\␣O␣O␣O␣/␣/ ␣\␣\␣_␣_␣/␣/ ␣␣\␣_␣_␣_␣/ ␣␣␣|␣␣_␣␣| ␣␣␣|␣|_|␣| ␣␣␣|_␣_␣_|
    ␣␣␣␣␣_␣_␣_␣_ ␣␣␣/␣␣_␣_␣_␣␣\ ␣␣/␣/␣O␣O␣O␣\␣\ ␣/␣/␣O␣O␣O␣O␣\␣\ /␣/␣O␣O␣O␣O␣O␣\␣\ \␣\␣O␣O␣O␣O␣O␣/␣/ ␣\␣\␣O␣O␣O␣O␣/␣/ ␣␣\␣\␣_␣_␣_␣/␣/ ␣␣␣\␣_␣_␣_␣_␣/ ␣␣␣␣|␣␣␣_␣␣␣| ␣␣␣␣|␣␣|_|␣␣| ␣␣␣␣|␣␣␣␣␣␣␣| ␣␣␣␣|_␣_␣_␣_|
   ␣␣␣␣␣␣_␣_␣_␣_␣_ ␣␣␣␣/␣␣_␣_␣_␣_␣␣\ ␣␣␣/␣/␣O␣O␣O␣O␣\␣\ ␣␣/␣/␣O␣O␣O␣O␣O␣\␣\ ␣/␣/␣O␣O␣O␣O␣O␣O␣\␣\ /␣/␣O␣O␣O␣O␣O␣O␣O␣\␣\ \␣\␣O␣O␣O␣O␣O␣O␣O␣/␣/ ␣\␣\␣O␣O␣O␣O␣O␣O␣/␣/ ␣␣\␣\␣O␣O␣O␣O␣O␣/␣/ ␣␣␣\␣\␣_␣_␣_␣_␣/␣/ ␣␣␣␣\␣_␣_␣_␣_␣_␣/ ␣␣␣␣␣|␣␣␣␣_␣␣␣␣| ␣␣␣␣␣|␣␣␣|_|␣␣␣| ␣␣␣␣␣|␣␣␣␣␣␣␣␣␣| ␣␣␣␣␣|␣␣␣␣␣␣␣␣␣| ␣␣␣␣␣|_␣_␣_␣_␣_|
   ␣␣␣␣␣␣␣_␣_␣_␣_␣_␣_ ␣␣␣␣␣/␣␣_␣_␣_␣_␣_␣␣\ ␣␣␣␣/␣/␣O␣O␣O␣O␣O␣\␣\ ␣␣␣/␣/␣O␣O␣O␣O␣O␣O␣\␣\ ␣␣/␣/␣O␣O␣O␣O␣O␣O␣O␣\␣\ ␣/␣/␣O␣O␣O␣O␣O␣O␣O␣O␣\␣\ /␣/␣O␣O␣O␣O␣O␣O␣O␣O␣O␣\␣\ \␣\␣O␣O␣O␣O␣O␣O␣O␣O␣O␣/␣/ ␣\␣\␣O␣O␣O␣O␣O␣O␣O␣O␣/␣/ ␣␣\␣\␣O␣O␣O␣O␣O␣O␣O␣/␣/ ␣␣␣\␣\␣O␣O␣O␣O␣O␣O␣/␣/ ␣␣␣␣\␣\␣_␣_␣_␣_␣_␣/␣/ ␣␣␣␣␣\␣_␣_␣_␣_␣_␣_␣/ ␣␣␣␣␣␣|␣␣␣␣␣_␣␣␣␣␣| ␣␣␣␣␣␣|␣␣␣␣|_|␣␣␣␣| ␣␣␣␣␣␣|␣␣␣␣␣␣␣␣␣␣␣| ␣␣␣␣␣␣|␣␣␣␣␣␣␣␣␣␣␣| ␣␣␣␣␣␣|␣␣␣␣␣␣␣␣␣␣␣| ␣␣␣␣␣␣|_␣_␣_␣_␣_␣_|
   Program Specification
1. The program first prompts the user for the side length 𝑛.
2. If 𝑛 is invalid (not between 3 and 29), the program prints an error message and terminates.
3. Print the machine capacity 𝑐, given by equation (1).
4. Prompt the user for the w**4;w**5;w**0;𝑐𝑘 of gumballs.
5. If w**4;w**5;w**0;𝑐𝑘 is invalid (not between ⌊𝑐/2⌋ and 𝑐), print an error message and terminate the program.
6. Print the gumball machine using loops and conditionals. This step comprises more subtasks like:
a. Determine the left padding, i.e., how many spaces to print before /, \ or | per row. b. Print the hexagonal part.
c. Align the current stock of gumballs properly inside the container.
d. Print the square part.
7. Prompt the user for the quantity w**2; to buy.
8. If w**2; is invalid (not between 1 and w**4;w**5;w**0;𝑐𝑘), print an error message and go back to step 6.
9. Deduct w**2; from w**4;w**5;w**0;𝑐𝑘.
10. If w**4;w**5;w**0;𝑐𝑘 > 0, go back to step 6.
11. Print the message "Sold out!" finally.
Note two important points:
• (Regarding 6.b) For a hexagon container full of gumballs, the number of gumballs varies by one
when going from one row to the next, except the two rows in the middle of the hexagon.
• (Regarding 6.c) Gumballs are dispensed or “consumed” in a top-to-bottom, left-to-right manner. The gumballs on the top row should be aligned to the right if their count is less than the row’s capacity (see Figure 1 again). Once consumed, the letter 'O' denoting a gumball will be replaced
by a space character.
Assumptions: You can assume that all user inputs are always entered as integers. The program behavior beyond this assumption can be indeterminate and your program behavior can be different from our sample program.
Copyright © 2024 CSE, CUHK Page 3 of 8

CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Restrictions: You are NOT allowed to use any arrays, vectors, or any other data containers in this assignment. You may use the string class (e.g., to store a line of characters if you see fit) but you cannot use its at() method or the subscript operator [] to traverse the individual characters of a string. Defining your own functions or macros is allowed but not mandatory.
Sample Runs
In the following sample runs, the blue numbers after ':' are user inputs and the other text is the program printout. You can try the provided sample program for other inputs. Your program printout shall be exactly the same as the sample program (same text, symbols, letter case, spacings, etc.). Note that there is a space after the ':' included in each input prompt.
    Enter side length: -1↵ Invalid side length!
Enter side length: 30↵ Invalid side length!
Enter side length: 4↵
Machine capacity: 21
Enter gumball stock: 9↵
Too few / many gumballs to load!
Enter side length: 4↵
Machine capacity: 21
Enter gumball stock: 22↵
Too few / many gumballs to load!
Enter side length: 6↵
Machine capacity: 65
Enter gumball stock: 31↵
Too few / many gumballs to load!
Enter side length: 4↵ Machine capacity: 21 Enter gumball stock: 10↵
____ /___\ // \\ // \\ // O\\ \\OOOOO// \\OOOO// \\___// \____/ |_|
| |_| | ||
|_ _ _ _|
Enter quantity to buy: 1↵ Copyright © 2024 CSE, CUHK
Page 4 of 8
          
CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
____ /___\ // \\ // \\ // \\ \\OOOOO// \\OOOO// \\___// \____/ |_|
| |_| | ||
|_ _ _ _| Enter quantity to ____ /___\ // \\ // \\ // \\ \\ // \\OOOO// \\___// \____/ |_|
| |_| | ||
|_ _ _ _| Enter quantity to Invalid quantity! ____ /___\ // \\ // \\ // \\ \\ // \\OOOO// \\___// \____/ |_|
| |_| | ||
|_ _ _ _| Enter quantity to ____ /___\ // \\ // \\ // \\ \\ // \\ // \\___// \____/ |_|
| |_| | ||
|_ _ _ _|
Sold out!
buy: 5↵
buy: 5↵
buy: 4↵
 Copyright © 2024 CSE, CUHK
Page 5 of 8

CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
 Enter side length: 5↵ Machine capacity: 40 Enter gumball stock: 25↵
_____ /____\ // \\ // \\ // \\ //OOOOOOO\\ \\OOOOOOO// \\OOOOOO// \\OOOOO// \\____// \_____/ |_|
| |_| | || ||
|_ _ _ _ _|
Enter quantity to buy: 26↵ Invalid quantity!
_____ /____\ // \\ // \\ // \\ //OOOOOOO\\ \\OOOOOOO// \\OOOOOO// \\OOOOO// \\____// \_____/ |_|
| |_| | || ||
|_ _ _ _ _|
Enter quantity to buy: 0↵ Invalid quantity!
_____ /____\ // \\ // \\ // \\ //OOOOOOO\\ \\OOOOOOO// \\OOOOOO// \\OOOOO// \\____// \_____/ |_|
| |_| | || ||
|_ _ _ _ _|
Enter quantity to buy: 10↵ Copyright © 2024 CSE, CUHK
Page 6 of 8

CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
_____ /____\ // \\ // \\ // \\ // \\ \\ OOOO// \\OOOOOO// \\OOOOO// \\____// \_____/ |_|
| |_| | || ||
|_ _ _ _ _|
Enter quantity to buy: 5↵ _____
/____\ // \\ // \\ // \\ // \\ \\ // \\ OOOOO// \\OOOOO// \\____// \_____/ |_|
| |_| | || ||
|_ _ _ _ _|
Enter quantity to buy: 10↵ _____
/____\ // \\ // \\ // \\ // \\ \\ // \\ // \\ // \\____// \_____/ |_|
| |_| | || ||
|_ _ _ _ _|
Sold out!
 Copyright © 2024 CSE, CUHK
Page 7 of 8

CSCI1120 Introduction to Computing Using C++, Fall 2024/25
Department of Computer Science and Engineering, The Chinese University of Hong Kong
Submission and Marking
§ Your program file name shall be gumball.cpp. Submit the file in Blackboard (https://blackboard.cuhk.edu.hk/).
§ Insert your name, student ID, and e-mail as comments at the beginning of your source file. // CSCI1120 Assignment 2
   // Name:
   // Student ID:
   // Email: (the one that you check most often)
§ You can submit your assignment multiple times. Only the latest submission counts.
§ Your program shall be free of compilation errors and warnings when built in VS Community 2022.
§ Your program shall include suitable comments as documentation.
§ Do NOT share your work to others and do NOT plagiarize. Both senders and plagiarists shall be
penalized.
           Copyright © 2024 CSE, CUHK Page 8 of 8

請加QQ:99515681  郵箱:99515681@qq.com   WX:codinghelp





 

掃一掃在手機打開當前頁
  • 上一篇:代做COMP3230、代寫c/c++編程設計
  • 下一篇:代寫ECON 3E03、代做R設計編程
  • 無相關信息
    合肥生活資訊

    合肥圖文信息
    2025年10月份更新拼多多改銷助手小象助手多多出評軟件
    2025年10月份更新拼多多改銷助手小象助手多
    有限元分析 CAE仿真分析服務-企業/產品研發/客戶要求/設計優化
    有限元分析 CAE仿真分析服務-企業/產品研發
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    急尋熱仿真分析?代做熱仿真服務+熱設計優化
    出評 開團工具
    出評 開團工具
    挖掘機濾芯提升發動機性能
    挖掘機濾芯提升發動機性能
    海信羅馬假日洗衣機亮相AWE  復古美學與現代科技完美結合
    海信羅馬假日洗衣機亮相AWE 復古美學與現代
    合肥機場巴士4號線
    合肥機場巴士4號線
    合肥機場巴士3號線
    合肥機場巴士3號線
  • 短信驗證碼 trae 豆包網頁版入口 目錄網 排行網

    關于我們 | 打賞支持 | 廣告服務 | 聯系我們 | 網站地圖 | 免責聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網 版權所有
    ICP備06013414號-3 公安備 42010502001045

    日韩精品一区二区三区高清_久久国产热这里只有精品8_天天做爽夜夜做爽_一本岛在免费一二三区

      <em id="rw4ev"></em>

        <tr id="rw4ev"></tr>

        <nav id="rw4ev"></nav>
        <strike id="rw4ev"><pre id="rw4ev"></pre></strike>
        亚洲欧美资源在线| 国产一区二区在线观看免费播放| 99在线热播精品免费| 亚洲欧美中文日韩在线| 老司机一区二区三区| 一本大道久久精品懂色aⅴ| 欧美电影免费| 欧美**字幕| 亚洲欧洲在线播放| 欧美系列一区| 亚洲国产综合91精品麻豆| 亚洲视频自拍偷拍| 一本久道久久综合中文字幕| 久久综合给合| 国产精品久久久久9999高清| 99这里只有久久精品视频| 在线看国产日韩| 一区二区三区精品在线| 99视频+国产日韩欧美| 亚洲视频你懂的| 国产真实乱子伦精品视频| 欧美日韩久久不卡| 亚洲视频大全| 国产日本欧美一区二区三区| 国产自产在线视频一区| 欧美一区二区免费视频| 欧美一区三区三区高中清蜜桃| 亚洲高清在线观看| 国产精品网红福利| 久久伊伊香蕉| 黄色成人在线网址| 在线成人免费视频| 亚洲网在线观看| 日韩一级裸体免费视频| 狠狠色2019综合网| 欧美一区二区精品| 国产精品一区久久| 久久久91精品国产一区二区精品| 久久国产精品久久久久久电车| 欧美日韩国内自拍| 欧美激情亚洲视频| 在线成人免费观看| 亚洲深夜福利网站| 亚洲香蕉成视频在线观看| 国产精品一区二区久久久| 亚洲素人在线| 1024成人| 亚洲美女av黄| 欧美韩日高清| 欧美国产第一页| 日韩一级黄色av| 欧美一级黄色网| 美女91精品| 欧美午夜精品一区二区三区| 亚洲亚洲精品三区日韩精品在线视频| 国产午夜精品久久久| 免费一级欧美在线大片| 欧美一区二区视频网站| 伊人男人综合视频网| 久久久精品2019中文字幕神马| 欧美成年人在线观看| 亚洲精品免费一区二区三区| 亚洲国产精品成人综合色在线婷婷| 亚洲承认在线| 久久青青草原一区二区| 国产亚洲精品美女| 欧美日韩精品免费看| 国产精品视区| 午夜性色一区二区三区免费视频| 欧美国产精品| 91久久精品日日躁夜夜躁欧美| 另类人畜视频在线| 欧美福利在线观看| 欧美一区二区久久久| 亚洲日本欧美天堂| 久久久精品一区二区三区| 欧美一区二区在线免费观看| 久久成人精品| 欧美女同在线视频| 欧美一区2区三区4区公司二百| 国语自产精品视频在线看一大j8| 亚洲欧美国产一区二区三区| 国产女同一区二区| 91久久国产自产拍夜夜嗨| 欧美日韩国产高清| a91a精品视频在线观看| 国产一区二区三区四区五区美女| 国产日韩一级二级三级| 欧美国产1区2区| 伊人色综合久久天天五月婷| 在线亚洲美日韩| 永久91嫩草亚洲精品人人| 欧美专区在线观看| 国产精品三级视频| 美日韩免费视频| 国产精品久久久久久模特| 欧美三级午夜理伦三级中文幕| 久久久久久久久岛国免费| 美女视频黄免费的久久| 99爱精品视频| 免费在线欧美视频| 国产精品久久久久9999吃药| 欧美黑人一区二区三区| 欧美日韩国产探花| 欧美麻豆久久久久久中文| 尤物视频一区二区| 亚洲视频在线观看三级| 国产精品九九| 欧美激情精品久久久久久免费印度| 国产精品福利久久久| 免费在线看成人av| 亚洲一区二区黄| 欧美精品一区在线| 国产亚洲aⅴaaaaaa毛片| 亚洲日本成人女熟在线观看| 亚洲欧美日韩国产精品| 亚洲你懂的在线视频| 日韩视频在线观看| 亚洲一级在线| 欧美日韩一区在线| 久久人人爽国产| 欧美日韩免费网站| 欧美影院在线| 国产真实乱子伦精品视频| 久久精品一区二区三区不卡| 欧美美女操人视频| 国产欧美日韩视频一区二区| 欧美高清视频免费观看| 亚洲影院免费观看| 国产精品qvod| 亚洲精品中文字幕在线观看| 欧美在线播放视频| 欧美激情一区二区三区不卡| 国产精品成人免费视频| 欧美一区午夜精品| 久久久久国产精品麻豆ai换脸| 一本久道久久综合婷婷鲸鱼| 亚洲欧洲日产国码二区| 麻豆乱码国产一区二区三区| 99精品国产在热久久婷婷| 欧美成人精品在线视频| 欧美视频亚洲视频| 国产精品mv在线观看| 亚洲精品小视频在线观看| 亚洲综合精品| 久久精品卡一| 国产日本欧洲亚洲| 欧美日韩视频在线第一区| 亚洲精品一区二区网址| 另类成人小视频在线| 尤物99国产成人精品视频| 国产亚洲精品久久久久婷婷瑜伽| 国产在线拍偷自揄拍精品| 欧美国产精品专区| 国产片一区二区| 亚洲欧洲美洲综合色网| 亚洲视频在线观看三级| 亚洲片国产一区一级在线观看| 久久久五月婷婷| 亚洲丁香婷深爱综合| 一区二区三区自拍| 亚洲伊人色欲综合网| 久久精品国产精品亚洲| 亚洲国产日韩一区|