Can I have regular function and class function together? if so, where should i place the regular function declaration? The compiler wouldn't compile this one... the problem is function showlist() Thank you
# include <iostream>
# include <string>
# include <fstream>
using namespace std;
class Name
{
public:
int id;
string lastName;
string firstName;
string phone;
double amt;
void output();
void set(int, string, string, string, double);
//void addName(int, Name);
};
void showlist();
int main()
{
/*
Name name[300];
ifstream reader;
reader.open("names.txt");
int i=0;
while(reader>>name[i].id>>name[i].lastName>>name[i].firstName>>name[i].phone>>name[i].amt)
{
i++;
}
cout<<"There are total "<<i<<" people in the list."<<endl;
cout<<endl;
for(int x=0; x<i; x++)
{
name[x].output();
}
*/
showlist();
return 0;
}
void showList()
{
Name name[300];
ifstream reader;
reader.open("names.txt");
int i=0;
while(reader>>name[i].id>>name[i].lastName>>name[i].firstName>>name[i].phone>>name[i].amt)
{
i++;
}
cout<<"There are total "<<i<<" people in the list."<<endl;
cout<<endl;
for(int x=0; x<i; x++)
{
name[x].output();
}
}
void Name::output()
{
cout<<id<<" "<<lastName<<" "<<firstName<<" "<<phone<<" "<<amt<<endl;
}
void Name::set(int inputID, string inputLastName, string inputFirstName, string inputPhone, double inputAmount)
{
id= inputID;
lastName = inputLastName;
firstName = inputFirstName;
phone= inputPhone;
amt = inputAmount;
}