如何解决此声明没有存储类或类型说明符 Error
大家好!我明天有一个项目要交,我不小心选择了一个很难的项目,现在我后悔了。我试图小规模地制作数字投票系统,只是为了代表我的想法,因为我是 BSCS 的第二学期学生。我自己制作了整个代码。我制作的第一个代码是工作代码,但输出不是我想要的。我想在投票后更改投票。但它并没有改变它。 这是下面的第一个代码:
#include<iostream>
#include<conio.h>
using namespace std;
void VoteLIST();
void VoteReturn();
class NADRA
{
protected:
double nic[4] = { {42401335},{1},{2},{3} };
int knum[4] = { {123},{3} };
int Vote[4] = { {0},{0},{0} };
void VoteCHANGE(int a,int b)
{
Vote[a] = b;
}
};
class CNIC :protected NADRA
{
private:
//nic = <=
double cnic;
int KhandaanNUM;
public:
CNIC()
{
cnic = KhandaanNUM = 0;
}
CNIC(double a,int b)
{
cnic = a;
KhandaanNUM = b;
}
void SetDATA(double a,int b)
{
cnic = a;
KhandaanNUM = b;
}
double getCNIC()
{
return cnic;
}
int getKNUM()
{
return KhandaanNUM;
}
int VoteSTATUS = 0;
bool check()
{
for (int loop = 0; loop < 4; loop++)
{
if (cnic == nic[loop] && KhandaanNUM == knum[loop] && (Vote[loop] == 0))
{
VoteSTATUS = Vote[loop];
return true;
break;
}
}
return false;
}
void setVote(int c)
{
//Vote[VoteSTATUS] = c;
VoteCHANGE(VoteSTATUS,c);
}
void VoteReturn()
{
cout << VoteSTATUS;
}
};
class Votemenu
{
private:
CNIC c1;
double Cnic;
int kNum;
public:
void GetData()
{
cout << "Enter CNIC: ";
cin >> Cnic;
cout << "Enter Khandaan Number: ";
cin >> kNum;
c1.SetDATA(Cnic,kNum);
}
void checkData()
{
if (c1.check() == true)
{
int choice;
system("cls");
VoteLIST();
cout << endl;
cout << "Please choose the Respective Party Number" << endl;
cin >> choice;
c1.setVote(choice);
system("cls");
cout << "You have successfully Voted for Party Number: " << choice <<endl;
}
else
{
system("cls");
cout << "You are not Eligible to Cast Vote!" << endl;
cout << "Reasons:\n1) CNIC or Khandaan Number You entered may be Incorrect";
cout << "\n2) You may not be 18 Above\n3) You may have already casted the Vote";
}
}
void Data2()
{
if (c1.check() == true)
{
system("cls");
cout << "Your CNIC Number: " << Cnic << endl;
cout << "Khandaan Number: " << kNum << endl;
cout << "You Have Voted for party number: "; c1.VoteReturn();
}
else
{
system("cls");
cout << "You are not Eligible to Cast Vote!" << endl;
cout << "Reasons:\n1) CNIC or Khandaan Number You entered may be Incorrect";
cout << "\n2) You may not be 18 Above\n3) You may have already casted the Vote";
}
}
};
void main()
{
while (true)
{
Votemenu v;
int choice;
system("cls");
cout << "Welcome To Vote Menu!" << endl;
cout << "Please choose any one of the following" << endl;
cout << "1) Cast Vote\n2) Check Vote";
cout << endl;
cin >> choice;
v.GetData();
if (choice == 1)
{
v.checkData();
_getch();
}
else if (choice == 2)
{
v.Data2();
_getch();
}
else
{
cout << "Wrong DATA:" << endl;
}
}
}
void VoteLIST()
{
cout << "Vote LIST" << endl;
cout << "1: PTI\n2:PMLN\n3:PPP\n4:MQM" << endl;
}
现在我尝试重新编写代码并添加文件流。从外部源获取文本,而不是在 Visual Studio 中创建数组并分配值。但现在我面临一个错误,它说此声明没有存储类或类型说明符代码如下:
#include<iostream>
#include<conio.h>
#include <fstream>
using namespace std;
void VoteLIST();
void VoteReturn();
class NADRA
{
protected:
fstream Text;
int nic[2];
int knum[2];
int Vote[2];
int count = 0;
int ccnic = 0;
int knumm = 0;
int Votee = 0;
Text.open("Nadra.txt")
{
while (!Text.eof())
{
Nadra >> ccnic >> knumm >> Votee;
nic[count] = ccnic;
knum[count] = knumm;
Vote[count] = Votee;
count++;
}
}
Text.close();
void VoteCHANGE(int a,kNum);
}
void checkData()
{
if (c1.check() == true)
{
int choice;
system("cls");
VoteLIST();
cout << endl;
cout << "Please choose the Respective Party Number" << endl;
cin >> choice;
c1.setVote(choice);
system("cls");
cout << "You have successfully Voted for Party Number: " << choice << endl;
}
else
{
system("cls");
cout << "You are not Eligible to Cast Vote!" << endl;
cout << "Reasons:\n1) CNIC or Khandaan Number You entered may be Incorrect";
cout << "\n2) You may not be 18 Above\n3) You may have already casted the Vote";
}
}
void Data2()
{
if (c1.check() == true)
{
system("cls");
cout << "Your CNIC Number: " << Cnic << endl;
cout << "Khandaan Number: " << kNum << endl;
cout << "You Have Voted for party number: "; c1.VoteReturn();
}
else
{
system("cls");
cout << "You are not Eligible to Cast Vote!" << endl;
cout << "Reasons:\n1) CNIC or Khandaan Number You entered may be Incorrect";
cout << "\n2) You may not be 18 Above\n3) You may have already casted the Vote";
}
}
};
void main()
{
while (true)
{
Votemenu v;
int choice;
system("cls");
cout << "Welcome To Vote Menu!" << endl;
cout << "Please choose any one of the following" << endl;
cout << "1) Cast Vote\n2) Check Vote";
cout << endl;
cin >> choice;
v.GetData();
if (choice == 1)
{
v.checkData();
_getch();
}
else if (choice == 2)
{
v.Data2();
_getch();
}
else
{
cout << "Wrong DATA:" << endl;
}
}
}
void VoteLIST()
{
cout << "Vote LIST" << endl;
cout << "1: PTI\n2:PMLN\n3:PPP\n4:MQM" << endl;
}
有人可以帮忙吗???明天是我最后一次约会了!我只希望我的程序从文本中获取数据,使用用户输入的数据检查数据,如果正确,它将继续并显示投票菜单。如果没有,它会给出错误等 我知道我是一个非常可悲的学习者。但是你们是专业的!我会从你身上学到很多东西。请帮帮我!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。