返回信息流#include<iostream>
#include<wks/sql_client>
using namespace std;
using namespace wks;
int main(int argc, char* argv[]) {
string name;
cout<<"Your name?"<<endl;
cin>>name;
if(name.length()>=0) {
string sex;
cout<<"Your sex?"<<endl;
cin>>sex;
if(sex=="male" || sex=="female") {
int age;
cout<<"Your age?"<<endl;
cin>>age;
if(age>0 && age<256) {
string school;
cout<<"What school are you in?"<<endl;
cin>>school;
if(school=="BUPT") {
int stu_num;
cout<<"Your student number:"<<endl;
cin>>stu_num;
if(0<stu_num && stu_num<999999) {
int class_id;
cout<<"Choose your course"<<endl;
cout<<"(1) Gao deng shu xue"<<endl;
cout<<"(2) Xian xing dai shu"<<endl;
cout<<"(3) Da xue wu li"<<endl;
cout<<"(4) Maozedong sixiang gailun"<<endl;
cin>>class_id;
if(1<=classid && classid<=4) {
cout<<"Please wait..."<<endl;
SqlConnection *connection = getConnection();
if(connection!=NULL) {
bool isBound = connection->bind("localhost",2048);
if(isBound) {
bool isConnected = connection->connect("xuanke.bupt.edu.cn");
if(isConnected) {
SqlQuery query = new query("INSERT (%d,%d) TO xuanke_table",stu_num,class_id);
bool isSuccessful = connection.execute(query);
if(isSuccessful) {
delete query;
bool isSuccessful2 = connection.close();
if(isSuccessful2) {
cout<<"选课成功。欢迎使用。"<<endl;
return 0;
} else {
cerr<<"Cannot close connection"<<endl;
}
} else {
cerr<<"Cannot execute query"<<enld;
return 1;
}
} else {
cerr<<"Cannot connect to server"<<enld;
return 1;
}
} else {
cerr<<"Cannot bind connection"<<enld;
return 1;
}
} else {
cerr<<"Cannot create connection"<<enld;
return 1;
}
} else {
cerr<<"Invalid course number"<<endl;
return 1;
}
} else {
cout<<"Student number invalid"<<endl;
return 1;
}
} else {
cerr<<"We only serve the BeiYouRen's. SOrry"<<endl;
return 1
}
} else {
cerr<"You lie! Tell the truth!"<<endl;
return 1;
}
} else {
cerr<<"Please enter either 'male' or 'female'"<<endl;
return 1;
}
} else {
cerr<<"Name too short"<<endl;
return 1;
}
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #18479同步于 2009/1/10
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
[代码美化向]这个代码如何修改
wks
2009/1/10镜像同步19 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
// 这个也好看不到哪里去。
#include<iostream>
#include<wks/sql_client>
using namespace std;
using namespace wks;
int main(int argc, char* argv[]) {
string name;
cout<<"Your name?"<<endl;
cin>>name;
if(name.length()==0) {
cerr<<"Name too short"<<endl;
return 1;
} else {
string sex;
cout<<"Your sex?"<<endl;
cin>>sex;
if(sex!="male" && sex!="female") {
cerr<<"Please enter either 'male' or 'female'"<<endl;
return 1;
} else {
int age;
cout<<"Your age?"<<endl;
cin>>age;
if(age<=0 || age>=256) {
cerr<"You lie! Tell the truth!"<<endl;
return 1;
} else {
string school;
cout<<"What school are you in?"<<endl;
cin>>school;
if(school!="BUPT") {
cerr<<"We only serve the BeiYouRen's. SOrry"<<endl;
return 1
} else {
int stu_num;
cout<<"Your student number:"<<endl;
cin>>stu_num;
if(stu_num<0 || stu_num>999999) {
cout<<"Student number invalid"<<endl;
return 1;
} else {
int class_id;
cout<<"Choose your course"<<endl;
cout<<"(1) Gao deng shu xue"<<endl;
cout<<"(2) Xian xing dai shu"<<endl;
cout<<"(3) Da xue wu li"<<endl;
cout<<"(4) Maozedong sixiang gailun"<<endl;
cin>>class_id;
if(classid< && classid>4) {
cerr<<"Invalid course number"<<endl;
return 1;
} else {
cout<<"Please wait..."<<endl;
SqlConnection *connection = getConnection();
if(connection==NULL) {
cerr<<"Cannot create connection"<<enld;
return 1;
} else {
bool isBound = connection->bind("localhost",2048);
if(!isBound) {
cerr<<"Cannot bind connection"<<enld;
return 1;
} else {
bool isConnected = connection->connect("xuanke.bupt.edu.cn");
if(!isConnected) {
cerr<<"Cannot connect to server"<<enld;
return 1;
} else {
SqlQuery query = new query("INSERT (%d,%d) TO xuanke_table",stu_num,class_id);
bool isSuccessful = connection.execute(query);
if(!isSuccessful) {
cerr<<"Cannot execute query"<<enld;
return 1;
} else {
delete query;
bool isSuccessful2 = connection.close();
if(!isSuccessful2) {
cerr<<"Cannot close connection"<<endl;
return 1;
} else {
cout<<"选课成功。欢迎使用。"<<endl;
return 0;
}
}
}
}
}
}
}
}
}
}
}
}
这种方式去掉else应该好看些
【 在 wks 的大作中提到: 】
: // 这个也好看不到哪里去。
: #include<iostream>
: #include<wks/sql_client>
: ...................
func1(){
subfunc1();
if (cond1 == false)
return (false);
subfunc2();
if (cond2 == false)
return (false);
do_a();
sub3();
if (cond3)
return (false);
return (0);
}
【 在 wks 的大作中提到: 】
: #include<iostream>
: #include<wks/sql_client>
: using namespace std;
: ...................
【 在 wks 的大作中提到: 】
: #include<iostream>
: #include<wks/sql_client>
: using namespace std;
: ...................
if(){
} else{
}
好看些还是
if()
{
}
else
{
}
好看些呢?
【 在 hg 的大作中提到: 】
: if(){
: } else{
: }
: ...................
第二种吧。。。上次咱老师给咱一个XXX标准来着,里面有讲这个