| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 410 人关注过本帖
标题:大家好!我是一名C语言的初学者!我请教个问题???
只看楼主 加入收藏
yy2954
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-10-12
收藏
 问题点数:0 回复次数:7 
大家好!我是一名C语言的初学者!我请教个问题???

Lab 1. Coin-changing and the Calculator
COMP Structured Programming
United International College

Introduction:

Now you are going to be a programming expert by exploring more in C programming! In this lab, you need to complete two tasks: a coin-changing program and a C calculator.

Task 1: Coin-Changing

You will write a coin-changing program for lab1. First, ask the user for the amount in
Hong Kong dollars, such as 56.30. Then find the minimum number of $10, $5, $2, $1, 50 cent, 20 cent, and 10 cent coins to give in return.

For example, your program first prompts the user for the amount in HKD by displaying the following message.

Please input the amount in Hong Kong dollars:

If the input is 56.30, the output should be

10-dollar coin: 5
5-dollar coin: 1
2-dollar coin: 0
1-dollar coin: 1
50-cent coin: 0
20-cent coin: 1
10-cent coin: 1

Task 2: A Calculator

Your second task is to write an integer arithmetic calculator.

Your calculator program should prompt the following UI (user interface) to the user.

-------------------
| 1 | 2 | 3 | + |
|-----------------|
| 4 | 5 | 6 | - |
|-----------------|
| 7 | 8 | 9 | * |
|-----------------|
| 0 | % | / | = |
-------------------
Please input the integer arithmetic expression (format: A op B =)

After the user input the expression in the correct format, your program calculates and displays the result. If the user inputs a illegal operator, your program should print the following message and ask the user to re-input it.

Sorry, you’ve input an wrong operator. Please enter the arithmetic expressions again.

A number can’t be divided by 0, so your program should be able to deal with this properly. When one calculation is completed, your program should ask user to input ‘Y’ or ‘N’ to indicate if anther calculation is needed.

Do you want to calculate again? (Y/N)

If the input is ‘Y’, then prompts the UI again. If the input is ‘N’, then ends the execution.

Hints:
1. Your program needs to decide what operation is to be used by checking the user input. This can be done by the so- “if… elseif…else” statement in C.

if(condition_1)
expression_1;
elseif(condition_2)
expression_2;
elseif(condition_3)
expression_3;
....
else(expression_k)


2. Your program will also need to decide whether the user wants to do another calculation or not. After knowing the answer is ‘Y’, the program needs to jump back to prompt the UI again. This can be done by using the ‘goto’ statement.

Display_UI: printf(“……..”); // this is the first line of displaying the UI

………………………..

goto Display_UI;

Marking Scheme:

Task 1: 30 marks
Task 2: 10 marks for displaying the UI
10 marks for each operator “+, -, *, /, %”
5 marks for division by 0 error processing
5 marks for code layout and proper comments

Deadline: You need to demonstrate your program to Dr. Amy Zhang or me by 5:00PM, Monday, Oct. 15.

搜索更多相关主题的帖子: C语言 
2007-10-12 15:53
yy2954
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-10-12
收藏
得分:0 
回复:(yy2954)大家好!我是一名C语言的初学者!我请教...
这个程序应该怎么写呢?
2007-10-12 15:57
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
收藏
得分:0 
Do you know english?

Repeat  Life=Study;Until (death);
2007-10-12 16:11
jianping814
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2007-10-12
收藏
得分:0 

太酷了,可惜我没看完


2007-10-12 16:13
yy2954
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-10-12
收藏
得分:0 
高手们,帮帮忙呀,急呀,
2007-10-12 16:13
yy2954
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-10-12
收藏
得分:0 

帮帮忙呀,我是一名学生呀,这是老师给我们的题呀,明天就要交了呀,

2007-10-12 16:31
偶是偶
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-10-12
收藏
得分:0 

哦额 刚看到版规里介绍的作业贴

2007-10-12 16:40
卓洛
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2007-10-11
收藏
得分:0 
我晕。。。
作业不会做就上网查。。。
2007-10-12 16:48
快速回复:大家好!我是一名C语言的初学者!我请教个问题???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017683 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved