|
|
帮帮忙!!谁会C++ PROGRAMMING?
[复制链接]
|
|
|

楼主 |
发表于 1-7-2009 11:31 AM
|
显示全部楼层
Write a cashier program that allows the cashier to enter the price and quantity of items and then display the total amount that needs to be paid.
In addition your cashier program needs to support the following features:
- Charge 5% tax to the total
- Round off cents based on the 1 cent rounding mechanism introduced by the government which is calculated after charging tax
- 1, 2, 6 and 7 rounded down to the nearest multiple of 5 cents
- 3, 4, 8 and 9 rounded up to the nearest multiple of 5 cents
做到我真的火了..=.=
#include<iostream>
#include<conio.h>
#define result
using namespace std;
void main(){
int quantity;
double price;
cin >> price;
cout << "Price per unit is " << price << endl;
cout << "Enter the quantity" << endl;
cin >> quantity;
cout << "The price is " << price * quantity << endl;
cout << "Adding 5% tax.." << price * quantity * 1.05 << endl;
_getch();
}
现在剩的是那个round up和round down..=,=
|
|
|
|
|
|
|
|
|
|
|
发表于 1-7-2009 10:17 PM
|
显示全部楼层
回复 21# emotion 的帖子
现在的学生
把最后一个数字乘于2, 大过5的就是要round up, 反之小过就round down(如果大过十就只拿个位数)
你的程序也没处理小数点... |
|
|
|
|
|
|
|
|
|
|
发表于 2-7-2009 02:50 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 2-7-2009 03:45 PM
|
显示全部楼层
原帖由 emotion 于 26-5-2009 03:53 PM 发表 
有点乱哦~~
教下我......
之前老师教我们做觉得容易..自己做就....
帮帮忙!!!感谢不尽!!!!
Write a program that receives an integer from the user. The program then displays as many prime numbers as th ...
//WK Lee@MMU, Jul 02 2009
#include <iostream>
#include <cstdlib>
using namespace std;
bool getPrime(int number)
{
bool rVal = true;
for(int i = 2; i < number; i++)
{
if((number%i) == 0)
rVal = false;
}
return rVal;
}
void getPrime()
{
int tPri;
int counter = 0;
int number = 2;
cout << "Total Prime Number Need To Generate: ";
cin >> tPri;
cout << "\r\nPrime Numbers: \r\n";
while(counter < tPri)
{
if(getPrime(number))
{
cout << number << "; ";
counter++;
}
number++;
}
cout << endl << endl;
}
char repeat()
{
char repeat;
do
{
cout << "Program end, do you wish to run again [Y/N]\r\n";
cin >> repeat;
}while((repeat != 'Y') && (repeat != 'y') && (repeat != 'N') && (repeat != 'n'));
return repeat;
}
int main()
{
char cont;
do
{
system("CLS");
getPrime();
cont = repeat();
}while((cont == 'Y') || (cont == 'y'));
system("PAUSE");
return 0;
} |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 2-7-2009 08:56 PM
|
显示全部楼层
原帖由 金旦面 于 2-7-2009 03:45 PM 发表 
//WK Lee@MMU, Jul 02 2009
#include
#include
using namespace std;
bool getPrime(int number)
{
bool rVal = true;
for(int i = 2; i < number; i++)
{
if((number%i) == 0)
rVal ...
排谢,
忘了告诉你们..
这问题已经solved liao. |
|
|
|
|
|
|
|
|
|
|
发表于 2-7-2009 10:04 PM
|
显示全部楼层
原帖由 金旦面 于 2-7-2009 03:45 PM 发表 
//WK Lee@MMU, Jul 02 2009
#include
#include
using namespace std;
bool getPrime(int number)
{
bool rVal = true;
for(int i = 2; i < number; i++)
{
if((number%i) == 0)
rVal ...
厉害就好,别假厉害。。。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 3-7-2009 12:18 AM
|
显示全部楼层
原帖由 emotion 于 2-7-2009 08:56 PM 发表 
排谢,
忘了告诉你们..
这问题已经solved liao.
今天得空就进来做一做测试基本功。
毕竟很久没动手。
有个网站名为cplusplus
内附所有cpp library的function解说。
对你来说应该有用,希望你能留意。
平心而论,国外的学生十多岁已经开始了解什么是programming logic。
写一个软件你必须了解,如何分析一个动作。
如一只手将东西抓起,移动去B点是多少步骤。
将手移动去那件东西的所在点已经包含了不少的动作(也属于步骤)。
而用手抓稳那件东西,然后提起该件东西已经是两个步骤。
整体来说,就是必须分析所有需要步骤,然后告诉电脑如何运作。
这属于编程逻辑。
这两个题目的步骤不算太多。
而且步骤可以重复。
你必须了解如何去分析。
举例来说,关于cashier的模式,那个round up的需求。
必须要确定你要做什么?
我们了解到1 cent到9 cent会被更改,那么我们现求得1 cent到9 cent的转换方法。
也就是如果 c==1将被替换为0,c==9将被替换为10。
那么我们就可以开始寻找如何得到cent的最后单位数。
首先就必须熟悉什么library有什么function能帮助你。
然后如何去运用就要多思考多练习。
我可以说你的tutor/lecturer不属于不负责任,毕竟大学与学院并非中学教育,所提倡的不是填鸭方式,更不是补习班。
任何lecturer提供的习题是一个基本而已,通常他需要你们利用这个基本开始思考然后变更。
更残酷一点,是学生的思维僵化,所以才有说老师blur blur,不懂教学等。
他不需要对无法跟进的人过渡关注,因为有这也属于一个还没进入社会的淘汰赛。
最重要的就是更改思维。
多和朋友同学正常讨论。
最重要就是你必须热爱编程。
否则到最后是非常辛苦。 |
|
|
|
|
|
|
|
|
|
|
发表于 3-7-2009 12:24 AM
|
显示全部楼层
原帖由 木村拓栽 于 2-7-2009 10:04 PM 发表 
厉害就好,别假厉害。。。。。
也没什么,基本功,就是思维和触觉。
做多了就是属于直觉,一看可以立刻知道问题要什么。
有经验就可以写出来。
甚至还可以追加其他,如在command prompt直接打primenumber.exe 20直接可以得到20个prime number,甚至是save to excel等等。
自己不行等于全世界都是如此。 |
|
|
|
|
|
|
|
|
|
|
发表于 3-7-2009 12:58 AM
|
显示全部楼层
原帖由 金旦面 于 3-7-2009 12:24 AM 发表 
也没什么,基本功,就是思维和触觉。
做多了就是属于直觉,一看可以立刻知道问题要什么。
有经验就可以写出来。
甚至还可以追加其他,如在command prompt直接打primenumber.exe 20直接可以得到20个prime numb ...
没有兴趣听你讲故事。。。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 6-7-2009 11:31 AM
|
显示全部楼层
不要忘记,
这里是大马,不是外国.
他们十几岁就会BASIC,并不代表我们大马的学生也会.
他们的教育程度跟我们是完全不一样的.
他们会,可能是他们自修学来的.
但据我所知,大马的学生在十几岁都在干嘛?
忙着进初中,认识新环境...
那时可能只会上网,连么是PROGRAMMING都不知道.
对于这些的,多数都是读完了SPM,进了自己想读的课程才学来的.
对,我的脑可能是属于僵硬的..
不懂的转弯..这一点我承认.
我是过来问怎样做,因为是没人可以教我了.
我的学院是分校来的,不是MAIN CAMPUS.
读IT的人是有限的.
请问我要跟谁请教?LECTURE?
那LECTURE都出了名教到学生MCC的..
我来这边问反而被...
无言..
不过还是谢谢指教.
希望那些如果没心要教的话,要来捣乱的话,
不要来泼冷水...
不要来说教..
那些自认自己很厉害的,
就请分享你们所会的,
而不是来这边讲好容易哦,这样都不会..
酱酱...不是来看你们炫耀的. |
|
|
|
|
|
|
|
|
|
|
发表于 7-7-2009 09:49 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 7-7-2009 10:14 PM
|
显示全部楼层
原帖由 yeenfei 于 7-7-2009 09:49 PM 发表 
我初二就会VB了。。还帮家里生意搞了个程序
到大学毕业为止,我的编程全是自修回来的。。。
lecturer会教到学生mcc是因为学生都在那边张嘴等喂饭。。。
还有重点,我没blog/facebook 时间可以花在 ...
我中二的时候只懂的上网,
programming是么我简直不知道.
我相信现在也是那样..
在大马的话初二的人会么?
打dota,online game..
programming?我相信可能才有5%的人自己自修去学..明白么来的..
如果我是从小就懂这些东西不要紧,
我刚学罢了,脑是属于比较慢的..
需要有人在一旁辅助..
我不是像你们那么聪明,厉害..
初二就懂这些,那些了..
还自修..
不懂当然就要问,要学..
问题是,问了还被泼冷水..
说这是基本的啦,那个啦,这个啦..这样都不会啊..那个啦..这个啦..
你们不愿教可以不要教,我没逼你们..
但是你们硬好去踩人,为何呢?
你们那样做很爽吗?
不好意思,语气过重了.
我只是表达我所想的罢了..
[ 本帖最后由 emotion 于 7-7-2009 10:21 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|
发表于 12-7-2009 07:21 PM
|
显示全部楼层
原帖由 emotion 于 7-7-2009 10:14 PM 发表 
我中二的时候只懂的上网,
programming是么我简直不知道.
我相信现在也是那样..
在大马的话初二的人会么?
打dota,online game..
programming?我相信可能才有5%的人自己自修去学..明白么来的..
如果我是从 ...
会被踩是因为你们没花心思去认真学习,
可能你们认为花些钱买本书回来翻翻就是'自学'吧,
对于书上的一切,有没有追根究底地研究为何如此呢?
学习必须包含理解的成分,不是拷贝内容罢了.
让自己的好奇心动起来就是最容易的学习动力,
我跟我朋友都是玩game时一边想象如果是自己,会如何以OO来表现game的设计 |
|
|
|
|
|
|
|
|
|
|
发表于 20-7-2009 01:13 AM
|
显示全部楼层
- #include <iostream>
- #include <cmath>
- using namespace std;
- double rounding(double input)
- {
- int cent = (int)((input - (int)input) * 100);
- cent = (cent % 10);
- int multiple = cent / 5;
- cent = cent % 5;
- if( cent >= 3 )
- multiple++;
-
- return (floor( input * 10 ) / 10) + ( multiple * 0.05 );
- }
- int main()
- {
- int quantity;
- double price;
- double total;
- double cent; // *********** unuse variale ************** 洗掉他吧
- cout << "Enter the unit price" << endl;
- cin >> price;
- cout << "The price is " << price << endl;
- cout << "Enter quantity" << endl;
- cin >> quantity;
- cout << "The price is " << price * quantity << endl;
- total = rounding((price * quantity * 105)/100); // this line changed
- cout << "Total after 5% tax " << total << endl;
- cout << total;
- return 0;
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|
发表于 20-7-2009 01:18 AM
|
显示全部楼层
老实说, 编程这条路只有真材实料的才能生存。
我并不是要数落你, 还是什么的。 不过这是学编程的一个好方法, 应该也是唯一的方法。
我们或许能给你 code, 但是你千万要记得去理解, 然后自行重新编写同样的程序。 理解程序的流程。 否则顶多 2 天, 你必定忘记这些 code 的。
编程真的要少玩多努力, 这个应该是每一个过来人会给说有初学者的忠告。 否则, 以后出来真的很困难阿 |
|
|
|
|
|
|
|
|
|
|
发表于 20-7-2009 01:29 AM
|
显示全部楼层
其实如果你仔细观察, 你应该会发现在软件界混的, 都是自学的。
不是软件界只有自学的来混,
而是只有自学的才能在软件界生存, 其余必定被淘汰。
说说我自己吧, 我中学毕业回到我小做 cp lab administrator , linux server administrator. 那是我的主任有请了一名印度妹来帮我, computer engineering diploma 的, 连 format 电脑也不懂。
又一次我蛮顶部顺的跟我主任投诉, 她久这样告诉我。
“她是永远薪水只有RM800的人, 你何必跟她计较?”
有文凭, 没“料”, 没用阿, 难道我们也要想他们这样, 一生薪水RM800 ? 努力很重要啊! 是时候改为前途着想了。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 20-7-2009 04:32 PM
|
显示全部楼层
谢谢你们的说教.
现在我的问题是..
- Round off cents based on the 1 cent rounding mechanism introduced by the government which is calculated after charging tax
- 1, 2, 6 and 7 rounded down to the nearest multiple of 5 cents
- 3, 4, 8 and 9 rounded up to the nearest multiple of 5 cents
#include<iostream>
#include <math.h>
#include<conio.h>
using namespace std;
void main()
{
int decimalPoint2;
int quantity;
double price,intPart1,intPart2, tempTotal,decimalPoint1;
double total,roundTotal;
double decimal, afterTax;
cout << "Enter the unit price" << endl;
cin >> price;
cout << "The price is " << price << endl;
cout << "Enter quantity" << endl;
cin >> quantity;
total = price * quantity;
cout << "The price is " << price * quantity << endl;
afterTax = total * 105;
decimal = modf(afterTax, &intPart1);
if(decimal>=0.5){
afterTax = ceil(afterTax);
}else{
afterTax = floor(afterTax);
}
afterTax = afterTax/100;
cout << "Total after 5% tax is " << afterTax << endl;
tempTotal = afterTax * 10;
decimalPoint1 = modf(tempTotal, &intPart2);
decimalPoint1 = decimalPoint1 * 10;
if((decimalPoint1==0)||(decimalPoint1==5)){
cout << "The round total is " << afterTax << endl;
}else{
if((decimalPoint1==1)||(decimalPoint1==6)){
afterTax = afterTax - 0.01;
cout << "The round total is " << afterTax << endl;
}
else{
if((decimalPoint1==2)||(decimalPoint1==7)){
afterTax = afterTax = afterTax - 0.02;
cout << "The round total is " << afterTax << endl;
}
else{
if((decimalPoint1==3)||(decimalPoint1==8)){
afterTax = afterTax + 0.02;
cout << "The round total is " << afterTax << endl;
}
else
{
if((decimalPoint1==4)||(decimalPoint1==9)){
afterTax = afterTax + 0.01;
cout << "The round total is " << afterTax << endl;
}
}
}
}
}
_getch();
}
我不知作么,那个if else part不work..
各位大大帮我看下是么问题..
[ 本帖最后由 emotion 于 20-7-2009 04:34 PM 编辑 ] |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 20-7-2009 04:43 PM
|
显示全部楼层
也是上个问题,
进位是可以了..但是..
先给你们看..
#include<iostream>
#include <math.h>
#include<conio.h>
using namespace std;
void main()
{
int decimalPoint2;
int quantity;
double price,intPart1,intPart2, tempTotal,decimalPoint1;
double total,roundTotal;
double decimal, afterTax;
cout << "Enter the unit price" << endl;
cin >> price;
cout << "The price is " << price << endl;
cout << "Enter quantity" << endl;
cin >> quantity;
total = price * quantity;
cout << "The price is " << price * quantity << endl;
afterTax = total * 105;
decimal = modf(afterTax, &intPart1);
if(decimal>=0.5){
afterTax = ceil(afterTax);
}else{
afterTax = floor(afterTax);
}
afterTax = afterTax/100;
cout << "Total after 5% tax is " << afterTax << endl;
tempTotal = afterTax * 10;
decimalPoint1 = modf(tempTotal, &intPart2);
decimalPoint2 = int(decimalPoint1 * 10);
cout << "The decimalPoint1 is " << decimalPoint1 << endl;
cout << "The decimalPoint2 is " << decimalPoint1 * 10 << endl;
switch(decimalPoint2){
case 0:case 5:
cout << "The round total is " << afterTax << endl;
break;
case 1:case 6:
afterTax = afterTax - 0.01;
cout << "The round total is " << afterTax << endl;
break;
case 2:case 7:
afterTax = afterTax - 0.02;
cout << "The round total is " << afterTax << endl;
break;
case 3:case 8:
afterTax = afterTax + 0.02;
cout << "The round total is " << afterTax << endl;
break;
case 4:case 9:
afterTax = afterTax + 0.01;
cout << "The round total is " << afterTax << endl;
break;
}
_getch();
}
你们试下price是9.7,
quantity是38,
price aftertax is 387.03,
it should rounds to 387.0,
但是却round to 387.01,么问题?
quantiti is 39也有这样的问题...
起初我以为是在1那边有问题..不过..
when price is 9.7, quantity is 33..
price aftertax is 336.11, it rounds to 336.1 <-- this one no problem..
怎么会那样..问题出在那里? |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|