反馈我的编程风格 [英] Feedback on my programming style

查看:58
本文介绍了反馈我的编程风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我编写的一个简单程序:


//此程序接收各种输入。

//计算当前余额是否超过信用额度。

//程序员:Nathan D. Brown

//日期:11/14/06


#包括< iostream>

#include< iomanip>

使用std :: cout;

使用std :: cin;

使用std :: endl;


int main()

{

int account_num;

double beg_bal;

double tot_charges;

double tot_credits;

double credit_limit;

double new_balance;


while(1){

cout<<"请输入帐号:( - 1到结尾)"<< endl;

cin>> account_num;

if(account_num == -1)

退出(1);

else {

cout<<"输入开头bal:"<< endl;

cin>> beg_bal;

cout<<"输入总ch arges:"<< endl;

cin>> tot_charges;

cout<<"输入总积分:"<< endl;

cin>> tot_credits;

cout<<"输入信用额度:"<< endl;

cin> > credit_limit;

new_balance = beg_bal + tot_charges -

tot_credits;

}


if (new_balance credit_limit){

cout<<"""" << :"<< credit_limit<< endl;

cout<<"" New Balance:"<<&new; new_balance<< endl;

cout<<"超出信用额度。"<< endl;

}


}

}


--------------------------------------- -----------------------------

------------- -------------------------------------------------- -----

-------------------


我需要一些简单的东西反馈:我的编程风格如何?我是否可以在代码中改进任何内容以获得更好的性能等等?

您提供的任何反馈都将获得极大的赞赏!!!!我打算用

为我的职业生涯编程。


再次感谢,


Nathan;)

-

--------------------------------- - - - -

发布于NewsLeecher v3.7 Final

Web @ http://www.newsleecher.com/?usenet

----------------- - ----- ---- - -

Here is a simple program that I wrote:

//This program takes in various inputs.
//It calculates if the current balance exceeds the credit limit.
//Programmer: Nathan D. Brown
//Date: 11/14/06

#include<iostream>
#include<iomanip>
using std::cout;
using std::cin;
using std::endl;

int main()
{
int account_num;
double beg_bal;
double tot_charges;
double tot_credits;
double credit_limit;
double new_balance;

while(1){
cout<<"Please enter account number:(-1 to end)"<<endl;
cin>>account_num;
if(account_num == -1)
exit(1);
else{
cout<<"Enter beginning bal:"<<endl;
cin>>beg_bal;
cout<<"Enter total charges:"<<endl;
cin>>tot_charges;
cout<<"Enter total credits:"<<endl;
cin>>tot_credits;
cout<<"Enter credit limit:"<<endl;
cin>>credit_limit;
new_balance = beg_bal + tot_charges -
tot_credits;
}

if(new_balance credit_limit){
cout<<"Acct number: "<<account_num<<endl;
cout<<"Credit limit: "<<credit_limit<<endl;
cout<<"New Balance: "<<new_balance<<endl;
cout<<"Credit limit exceeded."<<endl;
}

}
}

--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------

I need some simple feedback: How is my programming style? Can I
improve anything in the code for better performance etc?
ANY FEEDBACK YOU PROVIDE WILL BE GREATLY APPRECIATED!!!! I plan on
making programming into my career.

Thanks again,,

Nathan ;)
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.7 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

推荐答案

Nathan写道:
Nathan wrote:

这是我写的一个简单的程序:


//这个程序接受各种输入。

//它计算如果当前余额超过信用额度。

//程序员:Nathan D. Brown

//日期:11/14/06


#include< iostream>

#include< iomanip>

使用std :: cout;

使用std :: cin;

使用std :: endl;


int main()

{

in t account_num;

double beg_bal;

double tot_charges;

double tot_credits;

double credit_limit;

double new_balance;


while(1){

cout<<"请输入帐号:( - 1到结尾) "<< endl;

cin>> account_num;

if(account_num == -1)

exit(1) ;

else {

cout<<"输入开头bal:"<< endl;

cin>> beg_bal ;

cout<<"输入总费用:<<< endl;

cin>> tot_charges;

cout< ;<"输入总积分:"<< endl;

cin>> tot_credits;

cout<<"输入信用额度:" ;<< endl;

cin>> credit_limit;

new_balance = beg_bal + tot_charges -

tot_credits;

}


if(new_balance credit_limit){

cout<<"" Acct number:"<< account_num& lt;< endl;

cout<<"信用限额:"<<< credit_limit<< endl;

cout<<"新余额:"<<<&new;&new;<<&new;&new;<<<<&new;<<<<&new;<<<<<<<<<<<<<<<<<"""""" br $>

}

}


----------------- -------------------------------------------------- -

----------------------------------------- ---------------------------

--------------- ----


我需要一些简单的反馈:我的编程风格如何?我是否可以在代码中改进任何内容以获得更好的性能等等?

您提供的任何反馈都将获得极大的赞赏!!!!我打算在我的职业生涯中编程


Here is a simple program that I wrote:

//This program takes in various inputs.
//It calculates if the current balance exceeds the credit limit.
//Programmer: Nathan D. Brown
//Date: 11/14/06

#include<iostream>
#include<iomanip>
using std::cout;
using std::cin;
using std::endl;

int main()
{
int account_num;
double beg_bal;
double tot_charges;
double tot_credits;
double credit_limit;
double new_balance;

while(1){
cout<<"Please enter account number:(-1 to end)"<<endl;
cin>>account_num;
if(account_num == -1)
exit(1);
else{
cout<<"Enter beginning bal:"<<endl;
cin>>beg_bal;
cout<<"Enter total charges:"<<endl;
cin>>tot_charges;
cout<<"Enter total credits:"<<endl;
cin>>tot_credits;
cout<<"Enter credit limit:"<<endl;
cin>>credit_limit;
new_balance = beg_bal + tot_charges -
tot_credits;
}

if(new_balance credit_limit){
cout<<"Acct number: "<<account_num<<endl;
cout<<"Credit limit: "<<credit_limit<<endl;
cout<<"New Balance: "<<new_balance<<endl;
cout<<"Credit limit exceeded."<<endl;
}

}
}

--------------------------------------------------------------------
--------------------------------------------------------------------
-------------------

I need some simple feedback: How is my programming style? Can I
improve anything in the code for better performance etc?
ANY FEEDBACK YOU PROVIDE WILL BE GREATLY APPRECIATED!!!! I plan on
making programming into my career.



首先,在需要之前不要声明任何局部变量。

其次,初始化所有变量(至少在开始的

你的职业生涯。


定义了一个导致''退出''的分支(这通常很糟糕

想法,最好从任何函数优雅地返回,甚至''main''),

你不需要指定''else'',不必要的块导致

可见性混淆。


没有检查您的输入是否有效。如果我输入''abc''

你期望一个数字怎么办?定义读取数字可能更好。 kind

用于输入所有这些数字的功能。


只有一个提示指定了哪个值范围有效。是否接受了
的负数?


你的程序中没有任何东西需要或有任何机会

来提高性能,它'是一个UI程序(大部分时间花在

等待用户输入)并且计算很少。


使代码更具可读性:

使用空格而不是制表符。

带空格的环绕二元运算符(点和箭头除外)。


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要'请问

First of all, do not declare any local variables before you need them.
Second, initialise all your variables (at least in the beginning of
your career).

Having defined a branch that causes ''exit'' (which is generally a bad
idea, it''s better to return gracefully from any function, even ''main''),
you don''t need to specify ''else'', the unnecessary block causes
visibility confusion.

None of your input is checked for validity. What if I type ''abc'' where
you expect a number? It may be better to define a "read a number" kind
of function for entering all those numbers.

Only one of your prompts specifies what value range is valid. Are
negative numbers accepted?

There is nothing in your program that requires or has any opportunity
for performance improvement, it''s a UI program (most time is spent
waiting for user input) and there are very few calculations.

To make your code more readable:
Use spaces instead of tabs.
Surround binary operators (except dot and arrow) with spaces.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


dy****@hotmail.com 写道:
dy****@hotmail.com wrote:

这是我编写的一个简单程序:
Here is a simple program that I wrote:



#include< iostream>

#include< iomanip>


int main(int argc,char * argv []){


while(1 ){

int account_num = -1;

std :: cout<< 请输入帐号:( - 1到结尾) << std :: endl;

std :: cin> account_num;

if(account_num == -1){

break;

}

else {

double beg_bal = 0;

std :: cout<< 输入起始bal: << std :: endl;

std :: cin> beg_bal;

double tot_charges = 0;

std :: cout<< 输入总费用: << std :: endl;

std :: cin> tot_charges;

double tot_credits = 0;

std :: cout<< 输入总积分: << std :: endl;

std :: cin> tot_credits;

double credit_limit = 0;

std :: cout<< 输入信用额度: << std :: endl;

std :: cin> credit_limit = 0;

double new_balance = beg_bal + tot_charges - tot_credits;


if(new_balance credit_limit){

std :: cout<< "帐号: << account_num<< std :: endl;

std :: cout<< 信用额度: << credit_limit<< std :: endl;

std :: cout<< "新余额: << new_balance<< std :: endl;

std :: cout<< 超出信用额度。 << std :: endl;

}

}

}

返回0;

}

#include<iostream>
#include<iomanip>

int main(int argc, char* argv[]) {

while (1) {
int account_num = -1;
std::cout << "Please enter account number:(-1 to end)" << std::endl;
std::cin >account_num;
if (account_num == -1) {
break;
}
else {
double beg_bal = 0;
std::cout << "Enter beginning bal: " << std::endl;
std::cin >beg_bal;
double tot_charges = 0;
std::cout << "Enter total charges: " << std::endl;
std::cin >tot_charges;
double tot_credits = 0;
std::cout << "Enter total credits: " << std::endl;
std::cin >tot_credits;
double credit_limit = 0;
std::cout << "Enter credit limit: " << std::endl;
std::cin >credit_limit = 0;
double new_balance = beg_bal + tot_charges - tot_credits;

if(new_balance credit_limit) {
std::cout << " Acct number: " << account_num << std::endl;
std::cout << "Credit limit: " << credit_limit << std::endl;
std::cout << " New Balance: " << new_balance << std::endl;
std::cout << "Credit limit exceeded." << std::endl;
}
}
}
return 0;
}


我需要一些简单的反馈:我的编程风格如何?

我可以改进代码中的任何内容以获得更好的性能等吗?
I need some simple feedback: How is my programming style?
Can I improve anything in the code for better performance etc?



我不认为你的版本的工作方式应该是b
的工作方式。试试我的。


---- ==通过Newsfeeds.Com发布 - 无限制 - 无限制 - 安全使用网新闻== ----
http://www.newsfeeds.com 世界排名第一的新闻组服务! 120,000多个新闻组

---- =东和西海岸服务器农场 - 通过加密的总隐私= ----

I don''t think that your version worked the way that it was supposed to
work. Try mine instead.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----


实际上,


我的程序运行得很好。我正在使用microsoft visual studio

2005来编译代码。对不起,如果我有点新,但我是新手

程序员。我正在使用Deitel C ++如何编写书籍。他们

没有提到任何其他方法而不是我使用的方法。


感谢您的回复!


Nathan ;)

-

------------------------------ --- --- - -

发布于NewsLeecher v3.7 Final

Web @ http://www.newsleecher.com/?usenet

------------- ------ ----- ---- - -

Actually ,

My program works perfectly fine. I''m using microsoft visual studio
2005 to compile the code. Sorry if Im kind of new,,but im a novice
programmer. I''m using the Deitel C++ how to program book. They
didnt mention any other methods than the ones i used.

Thanks for your responses!

Nathan ;)
--
--------------------------------- --- -- -
Posted with NewsLeecher v3.7 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -


这篇关于反馈我的编程风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆