Anyone please take a look at the set() ... i don't know what went wrong that string in the set() gave me compile error saying undeclared identifier, which shouldn't even be a variable

# 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);

	};

	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++;
		}
		*/
		
		
name[0].set(123, aLastName, aFirstName, 617-538-2888, 1000.00);  // aLastName and                               aFirstName gave compiling error...

		
		
		/*
		for(int x=i-1; x>-1; x--)
		{
		name[x].output();
		
		}
		*/

		return 0;
	}

	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;
	}

With the architecture you provided you don't need any set member function. You can access the variables by using .

class Name
{
private:
  int id;
  string lastName;
  string firstName;
  string phone;
  double amt;
  
public:
  void output();
  void set(int, string, string, string, double);

};

I believe is what you were meaning?

Anyway, that wasn't your question.
>> name[0].set(123, aLastName, aFirstName, 617-538-2888, 1000.00);
This is where your problem is. aLastName, aFirstName, and the first number aren't strings. They 'look like' variable-names to your compiler, but, of course, they haven't been declared... so it says they don't exist. You could do: name[0].set(123, "aLastName", "aFirstName", "617-538-2888", 1000.00); , or declare and set variables by the name of the parameters before calling the set member if you want and that should work.

twomers,
hey, thx alot. I forgot the basic basic..... i appreciate your great help. thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.