| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 699 人关注过本帖
标题:C++中投票问题遇到的困难,大侠们帮忙啊
取消只看楼主 加入收藏
hong4781798
Rank: 1
来 自:中国河北
等 级:新手上路
帖 子:28
专家分:0
注 册:2010-4-17
结帖率:90%
收藏
已结贴  问题点数:20 回复次数:0 
C++中投票问题遇到的困难,大侠们帮忙啊
题目要求:投票管理需求
预先指定若干名侯选人(最多12人)
预先指定当选标准(给定百分数)
提供投票功能(不可以选非侯选人)
支持选举结果的输出(当选人和票数)
下面是我写的程序:
demo.h
struct Candidate
{
  char name;//候选人名字
  int amount;//所得的票数
};
class Demo
{
public:   
    Candidate can[3];
public:
    void demo();
    int Iseffvote(char s,Candidate *x);
    int Result();
};
demo.cpp
#include<iostream.h>
#include <stdio.h>
#include "demo.h"
void demo()
{
  Candidate can[3]={{'a',0},{'b',0},{'c',0}};
}
int Iseffvote(char s,Candidate *x)//*判断输入的候选人是否在指定的当中,是的话相应的票数增加*//
{     Demo d=new demo();   
    *x=d.can[0];
    int flag=0;   
      for(int i=0;i<3;i++)
    {
      if(s==d.can[i].name)      {d.can[i].amount++;flag=1;}
    }   
   if(flag==0)
   cout<< "Input wrong!Please vote one of the candidate again!" <<endl;
   return 0;
   
}
 int Result()//*得出结果   如何将上面已经进行加操作的各个的票数带进来,进行下一步的操作???
 { Demo d;
  int flag=0;
  int n;double m[3];
  for(int i=0;i<3;i++)
      n+=d.can[i].amount;  
  for(int j=0;j<3;j++)
      m[j]=d.can[j].amount/n;
  for(int r=0;r<3;r++)
  {
      if(m[r]>0.5)  
      {
          cout <<"The winner is" <<d.can[r].name<<"and the amount of vote is " <<d.can[r].amount <<endl;
          flag=1;
      }
  }
  if(flag==0)  cout << "The result is none,because the percent of every candidate is below 50%."<<endl;
  return 0;
}
 void main()
 {
   Demo t=new demo();
  cout << "The candidates are " << t.can[0].name <<endl<<t.can[1].name<<endl <<t.can[2].name <<endl;
   cout <<"Please choose one of them:"<<endl;
   char c;   
   cin >> c;
   while(c=='a'||c=='b'||c=='c')  {n=t.Iseffvote(c,t.can);}
   t.Result();
 }
 但是运行后出现的错误信息提示是:
F:\OOP\demo.cpp(9) : error C2061: syntax error : identifier 'demo'
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ')' before ';'
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ';' before ')'
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ';' before ')'
F:\OOP\demo.cpp(12) : warning C4552: '<' : operator has no effect; expected operator with side-effect
F:\OOP\demo.cpp(12) : error C2143: syntax error : missing ';' before ')'
F:\OOP\demo.cpp(13) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.

demo.obj - 1 error(s), 0 warning(s)
希望大侠们帮帮忙啊
搜索更多相关主题的帖子: 困难 投票 
2010-09-19 18:07
快速回复:C++中投票问题遇到的困难,大侠们帮忙啊
数据加载中...
 
   



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

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