- #include<iostream>
- using namespace std;
- #include<fstream>
- class questionaire
- {
- char answer[24][6];// 每题的答案临时变量
- int finalanswer[24][6];//储存最后的答案,6位代表a-f,选了就为1
- int flag[24];//题目完成与否的标记
- public:
- void showthanks();//显示感谢词
- int checkall();//检查问卷完成的完整性,完成则返回0,否则返回题号
- int getanswer(int form,int number);//检查合法的答案输入,并返回可能的选择,L为1,N为2,否则为0
- int getanswerln(char ch[]);//判断是否是功能选项
- int legal1(int form,char ch[]);//判断选项是否合法
- void showinformation();
- void getfinalanswer(int i);//将获得的数据进行处理的部分,i题号
- void showresult();//显示测试结果
- void change(int form,char ch[]);//大写转换成小写
- void showtopic(int &i);//显示题目
- questionaire();
- void outputfinal();//输出最后结果
- };
- questionaire::questionaire()
- {
- for(int i=0;i<24;i++)
- {
- flag[i]=0; //必须进行初始化,否则出错
- for(int j=0;j<6;j++)
- finalanswer[i][j]=0;
- }
- }
- void questionaire::showtopic(int &i)
- {
- int form;
- switch(i)
- {
- case 1:
- {
- form=3;
- cout<<"您的性别:"<<endl;
- cout<<"A.男 B.女"<<endl;
- if(getanswer(form,i)==1);
- else
- i++;
- }
- break;
- case 2:
- {
- form=1;
- cout<<"您现在所处年级:"<<endl;
- cout<<"A.大一 B.大二 C.大三 D.大四"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 3:
- {
- form=1;
- cout<<"请问您每周的课外阅读时间一般是多少?"<<endl;
- cout<<"A.一小时以及一小时以下 B.一到两小时 C.两到三小时 D.三小时以上"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 4:
- {
- form=2;
- cout<<"请问您每天课外阅读时间是____"<<endl;
- cout<<"A.固定的 B.有时间就看看 C.不确定"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 5:
- {
- form=2;
- cout<<"如果一本很好的课外阅读读物你会多久读完?"<<endl;
- cout<<"A.一口气读完(能尽快读完) B.每天花段时间阅读(慢慢的品味) C.经常反复的看(细细回味)"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 6:
- {
- form=3;
- cout<<"您觉得大学生应该每天花时间进行课外阅读吗?"<<endl;
- cout<<"A.应该 B.不应该"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 7:
- {
- form=1;
- cout<<"请问您一年一般能阅读几本课外书籍?"<<endl;
- cout<<"A.一本以及一本以下 B.一本到三本 C.三本到四本 D.四本以上"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 8:
- {
- form=1;
- cout<<"请问您一年课外阅读的书数量占您一年中阅读书籍数量的比例是:"<<endl;
- cout<<"A.25%及以下 B.25%~50% C.50~75% D.75%及以上"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 9:
- {
- form=3;
- cout<<"您的阅读数量会受外界因素的影响吗?"<<endl;
- cout<<"A.会 B.不会"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 10:
- {
- form=3;
- cout<<"您的阅读是否存在自己的计划?"<<endl;
- cout<<"A.存在 B.不存在"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 11:
- {
- form=4;
- cout<<"请问您一般阅读的内容是什么?(多选)"<<endl;
- cout<<"A.文学类 B.娱乐消遣类 C.应用技术类 D.专业书籍 E.科普读物 F.其他"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 12:
- {
- form=2;
- cout<<"您对您自己阅读的内容看法"<<endl;
- cout<<"A.范围不广,仅限于自己喜欢的 B.范围广,但是不精 C.挺满意的"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 13:
- {
- form=5;
- cout<<"请问什么是影响您课外阅读内容的因素(多选)"<<endl;
- cout<<"A.情感以及个人困惑 B.专业知识装备 C.休闲娱乐 D.个人兴趣 E.其他"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 14:
- {
- form=1;
- cout<<"你所读的课外书多来自:"<<endl;
- cout<<"A. 图书馆借的 B. 书店买的 C.电子版的 D.其他"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 15:
- {
- form=2;
- cout<<"传统阅读与网络在线阅读,您更喜欢:"<<endl;
- cout<<"A.传统阅读 B.网络在线阅读 C.不确定"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 16:
- {
- form=4;
- cout<<"您喜欢的书籍类型有:(多选)"<<endl;
- cout<<"A.文学 B.生活 C.科学 D.娱乐 E.理财 F.其他"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 17:
- {
- form=2;
- cout<<"您平时喜欢阅读什么样的书籍:"<<endl;
- cout<<"A.正版书籍(即求质量,又保证内容) B.便宜的盗版书籍(只求内容)C.无所谓(只要是自己要的书就行)"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 18:
- {
- form=5;
- cout<<"在业余生活中,你对哪一种形式的活动更感兴趣?(多选)"<<endl;
- cout<<"A.上网 B.读课外书 C.看电视,听广播 D.参加体育活动 E.其他"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 19:
- {
- form=1;
- cout<<"请问您阅读的书一般来自于:"<<endl;
- cout<<"A.朋友馈赠 B.自己购买 C.家长购买 D.从不买书,只是借阅"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 20:
- {
- form=1;
- cout<<"你平均每学期用于购买课外书的消费:"<<endl;
- cout<<"A.20元以上 B.10-20元 C.5-10元 D.5元以下"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 21:
- {
- form=3;
- cout<<".假使考试之前书店有两本书很紧销,但受条件限制你只能买一本,这两本书分别是:第一本关注当今热门现象,你很感兴趣,第二本与考试内容有关指导你考一个好成绩.在这种情况下,你通常回选择:"<<endl;
- cout<<"A.第一本 B. 第二本"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 22:
- {
- form=4;
- cout<<"在寒暑假你更愿意读什么(多选)"<<endl;
- cout<<"A.娱乐类书籍 B.专业书籍 C.应用技术类(如计算机,英语) D.文学类 E.科普读物"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 23:
- {
- form=3;
- cout<<"你在考虑课阅读内容时,是从何种角度出发"<<endl;
- cout<<"A.满足社会的需要 B.满足个人的需要"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- case 24:
- {
- form=1;
- cout<<"当前你读课外书的主要目的"<<endl;
- cout<<"A.备考 B.扩大知识面 C.充实自己 D.兴趣"<<endl;
- if(getanswer(form,i)==1)
- i=i-1;
- else
- i++;
- }
- break;
- }
- }
- int questionaire::checkall()
- {
- for(int i=0;i<24;i++)
- {
- if(!flag[i])
- return i+1;
- }
- return 0;
- }
- void questionaire::showthanks()
- {
- cout<<"本次调查采用选择和填空的形式进行,请您抽出您宝贵的一点时间来配合我们完成此次调查,"
- "本次调查涉及到的个人信息均只用于此次调查,不会另作它用,请您根据您的实际情况,如实作答,谢谢您的合作。"<<endl<<
- "按确认键继续……";
- }
- void questionaire::change(int form,char ch[])
- {
- int length=strlen(ch);
- switch(form)
- {
- case 1:
- case 2:
- case 3:
- {
- if(strcmp(ch,"A")>=0&&strcmp(ch,"D")<=0)
- ch[0]=ch[0]+32;
- }
- break;
- case 4:
- case 5:
- {
- for(int i=0;i<length;i++)
- if(strcmp(ch,"A")>=0&&strcmp(ch,"F")<=0)
- ch[i]=ch[i]+32;
- }
- break;
- }
- }
- int questionaire::getanswer(int form,int number)
- {
- number=number-1;
- if(flag[number]==1)
- {
- cout<<"您之前的选择是:"<<answer[number]<<"如需更改请重新键入您的选择"<<endl;
- }
- cout<<"您的选择是:";
- char ch[6];
- cin>>ch;
- //cin>>answer[number];
- //change(form,answer[number]);
- if(!getanswerln(ch))
- {
- while(legal1(form,ch))
- {
- cout<<"输入有误,没有这个选项,请重新输入:";
- cin>>ch;
- if(getanswerln(ch))
- break;
- //cin>>answer[number];
- //int length=strlen(ch);
- }
- int returnnumber=getanswerln(ch);
- if(returnnumber!=0)
- return returnnumber;
- else
- {
- flag[number]=1;
- strcpy(answer[number],ch);
- change(form,answer[number]);
- cout<<"ok"<<endl;
- return 0;
- }
- }
- else
- return getanswerln(ch);
- }
- int questionaire::getanswerln(char ch[])
- {
- if(strlen(ch)>1)//多选了,直接否认选择前后
- return 0;
- if(!strcmp(ch,"l")|!strcmp(ch,"L"))//前一题的指令
- return 1;
- else if(!strcmp(ch,"n")|!strcmp(ch,"N"))//后一题的指令
- return 2;
- return 0;
- }
- int questionaire::legal1(int form,char ch[])
- {
- int length=strlen(ch);
- switch(form)
- {
- //前面三种代表检查单选三种题目 后面是检查多选的
- case 1:
- {
- if(strcmp(ch,"A")<0||(strcmp(ch,"D")>0&&strcmp(ch,"a")<0)||strcmp(ch,"d")>0||length>1)
- return 1;
- else
- return 0;
- }
- break;
- case 2:
- {
- if(strcmp(ch,"A")<0||(strcmp(ch,"C")>0&&strcmp(ch,"a")<0)||strcmp(ch,"c")>0||length>1)
- return 1;
- else
- return 0;
- }
- break;
- case 3:
- {
- if(strcmp(ch,"A")<0||(strcmp(ch,"B")>0&&strcmp(ch,"a")<0)||strcmp(ch,"b")>0||length>1)
- return 1;
- else
- return 0;
- }
- break;
- case 4:
- {
- for(int i=0;i<length;i++)
- {
- if(strcmp(&ch[i],"A")<0||(strcmp(&ch[i],"F")>0&&strcmp(&ch[i],"a")<0)||strcmp(&ch[i],"f")>0)
- return 1;
- }
- return 0;
- }
- break;
- case 5:
- {
- for(int i=0;i<length;i++)
- {
- if(strcmp(&ch[i],"A")<0||(strcmp(&ch[i],"E")>0&&strcmp(&ch[i],"a")<0)||strcmp(&ch[i],"e")>0)
- return 1;
- }
- return 0;
- }
- break;
- }
- }
- void questionaire::showinformation()
- {
- cout<<"输入l,返回上一题,输入n跳至下一题(大小写不限)"<<endl;
- }
- void questionaire::getfinalanswer(int i)
- {
- int length=strlen(answer[i]);
- switch(length)
- {
- case 1:
- {
- int number;
- number=answer[i][0]%'a';
- //cout<<number<<endl;
- finalanswer[i][number]=1;
- }
- break;
- default:
- {
- for(int j=0;j<length;j++)
- finalanswer[i][answer[i][j]%'a']=1;
- }
- break;
- }
- }
- void questionaire::showresult()
- {
- for(int i=0;i<24;i++)
- {
- cout<<i<<" "<<answer[i]<<endl;
- }
- }
- void questionaire::outputfinal()
- {
- char filename[]="调查问卷结果.dat";
- fstream outfile(filename,ios::out);
- if(!outfile)
- {
- cerr<<"open error"<<endl;
- }
- else
- {
- for(int topicnumber=0;topicnumber<24;topicnumber++)
- {
- for(int line=0;line<6;line++)
- outfile<<finalanswer[topicnumber][line]<<" ";
- outfile<<endl;
- }
- }
- }
- main()
- {
- questionaire test;
- test.showthanks();
- cin.get();
- for(int i=1;i<=24;)
- {
- system("cls");
- test.showinformation();
- cout<<i<<". ";
- test.showtopic(i);
- }
- int number;
- while(number=test.checkall())
- {
- system("cls");
- cout<<"您未完成所有题目,请继续完成:"<<endl;
- test.showtopic(number);
- }
- system("cls");
- test.showresult();
- for(int i=0;i<24;i++)
- test.getfinalanswer(i);
- test.outputfinal();
- system("pause");
- }
几天的成果…与大家分享下…本人技艺不精…暂时还只能做DOS版的
希望有人点拨啊