I have written this program to test out my newly gained knowledge on classes, but my compiler (Dev-C++... soon getting MSVC++) says that I havn't declared to variables inside the class. To help you understand my problem, here are the errors....
Code:
c:\mydocu~1\people.cpp: In function `void outPutCiv()':
c:\mydocu~1\people.cpp:38: `name' undeclared (first use this function)
c:\mydocu~1\people.cpp:38: (Each undeclared identifier is reported only once
c:\mydocu~1\people.cpp:38: for each function it appears in.)
c:\mydocu~1\people.cpp:40: `creditCard' undeclared (first use this function)
c:\mydocu~1\people.cpp:42: `extra' undeclared (first use this function)
...and here is the actual code....
Code:
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <fstream.h>
class civillian
{
public:
char name[128];
int creditCard;
char extra[128];
};
class government
{
public:
char name[128];
int creditCard;
char extra[128];
};
class military
{
public:
char name[128];
int creditCard;
char extra[128];
};
void outPutCiv()
{
ofstream output;
output.open("data.txt");
output << " Data for a Civillian\n\n";
output << "Name: ";
output << name.person;
output << "\nCredit Card number: ";
output << creditCard.person;
output << "\nExtra information: ";
output << extra.person;
output.close();
}
void outPutGov()
{
ofstream output;
output.open("data.txt");
output << " Data for a Government person\n\n";
output << "Name: ";
output << name.person1;
output << "\nCredit Card number: ";
output << creditCard.person1;
output << "\nExtra information: ";
output << extra.person1;
output.close();
}
void outPutMil()
{
ofstream output;
output.open("data.txt");
output << " Data for a Military person\n\n";
output << "Name: ";
output << name.person2;
output << "\nCredit Card number: ";
output << creditCard.person2;
output << "\nExtra information: ";
output << extra.person2;
output.close();
}
void civInfo()
{
cout << "Enter the information for a civillian:\n";
cout << "Enter your name: ";
cin.getline(name.person, 128);
cout << "Enter your credit card number: ";
cin >> creditCard.person;
cout << "Enter any extra information about this person: ";
cin.getline(extra.person, 128);
outPutCiv();
}
void govInfo()
{
cout << "Enter the information for a Government person:\n";
cout << "Enter your name: ";
cin.getline(name.person1, 128);
cout << "Enter your credit card number: ";
cin >> creditCard.person1;
cout << "Enter any extra information about this person: ";
cin.getline(extra.person1, 128);
outPutGov();
}
void milInfo()
{
cout << "Enter the information for a Military person:\n";
cout << "Enter your name: ";
cin.getline(name.person2, 128);
cout << "Enter your credit card number: ";
cin >> creditCard.person2;
cout << "Enter any extra information about this person: ";
cin.getline(extra.person2, 128);
outPutMil();
}
int main()
{
civillian person;
government person1;
military person2;
cout << "Welcome to Chris' person-data application\n";
cout << "Are you entering the data for a:\n";
cout << "[1]Civillian\n[2]Government person\n[3]Military person\n";
int choice = 0;
cin >> choice;
switch (choice)
{
case 1:
system("cls");
civInfo();
break;
case 2:
system("cls");
govInfo();
break;
case 3:
system("cls");
milInfo();
default:
cout << "You must enter a number between 1 and 3";
}
return 0;
}
Hope somebody can solve this mind buggling mystery
Thanks
-Chris