Sntax Error

Hi guys: Can any one please help me in that error. Thanks.

class Employee
{
      public:
             string name;
             double salary;
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}


Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:5: error: `string' does not name a type

C:\Documents and Settings\Kathy\My Documents\test.cpp:11: error: definition of implicitly-declared `Employee::Employee()'
C:\Documents and Settings\Kathy\My Documents\test.cpp:11: error: declaration of `Employee::Employee()' throws different exceptions
C:\Documents and Settings\Kathy\My Documents\test.cpp:3: error: than previous declaration `Employee::Employee() throw ()'
C:\Documents and Settings\Kathy\My Documents\test.cpp: In constructor `Employee::Employee()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: `name' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `,' or `;' before "n"

Execution terminated
mustish1Asked:
Who is Participating?
 
brendanmeyerConnect With a Mentor Commented:
replace every
 "string"
with
"std::string"
0
 
brendanmeyerCommented:
is this c++ or c#?

I think it should be: (sorry if not 100% correct)
c#
class Employee
{
      public:
             string name;
             double salary;

      Employee()
      {
          name = "";
          salary = 0.0;
      }

      Employee(string n, double s)
      {
        name = n;
        salary = s;
      }
}

Open in new window


c++
class Employee
{
      public string name;
      public double salary;

      public Employee();
      public Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

Open in new window

0
 
mustish1Author Commented:
Thanks. Its a C++

class Employee
{
      public string name;
      public double salary;

      public Employee();
      public Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}



Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:3: error: expected `:' before "string"
C:\Documents and Settings\Kathy\My Documents\test.cpp:3: error: `string' does not name a type
C:\Documents and Settings\Kathy\My Documents\test.cpp:4: error: expected `:' before "double"
C:\Documents and Settings\Kathy\My Documents\test.cpp:6: error: expected `:' before "Employee"

C:\Documents and Settings\Kathy\My Documents\test.cpp:7: error: expected `:' before "Employee"

C:\Documents and Settings\Kathy\My Documents\test.cpp:7: error: expected `)' before "n"

C:\Documents and Settings\Kathy\My Documents\test.cpp: In constructor `Employee::Employee()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: `name' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:16: error: expected `,' or `;' before "n"

Execution terminated
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
brendanmeyerCommented:
sorry i did the class declaration
 
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

Open in new window

0
 
brendanmeyerCommented:
i think i have gotten a little bit confused.

are you including a header for the type "string"?
0
 
mustish1Author Commented:
Thanks. It still give error on that line
string name;

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:17: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:17: error: expected `,' or `;' before "n"

Execution terminated


class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
0
 
brendanmeyerCommented:
is that the whole cpp file?
0
 
mustish1Author Commented:
#include<iostream>
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
0
 
mustish1Author Commented:
Yes.
0
 
brendanmeyerCommented:
#include<iostream>

class Employee
{
      public:
            std::string name;
            double salary;

            Employee();
            Employee(std::string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(std::string n, double s)
{
  name = n;
  salary = s;
}

Open in new window

0
 
mustish1Author Commented:
im sorry. I think main is missing in that. I am just trying to play with the object oriented programming.
0
 
brendanmeyerCommented:
yer you need a main

also you need to add
std:: before and string declarations
eg:
std::string name;
0
 
mustish1Author Commented:
Can you please tell me the changes in the code



class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

int main()
#include<iostream>
{
      system("pause");
      return 0;
}
0
 
brendanmeyerCommented:
from you original?

#include<iostream> should be at the top of the file
0
 
mustish1Author Commented:
Compiler: Default compiler
Executing  g++.exe...
g++.exe "C:\Documents and Settings\Kathy\My Documents\test.cpp" -o "C:\Documents and Settings\Kathy\My Documents\test.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\Documents and Settings\Kathy\My Documents\test.cpp:5: error: `string' does not name a type

C:\Documents and Settings\Kathy\My Documents\test.cpp:9: error: expected `)' before "n"

C:\Documents and Settings\Kathy\My Documents\test.cpp: In constructor `Employee::Employee()':
C:\Documents and Settings\Kathy\My Documents\test.cpp:14: error: `name' undeclared (first use this function)
C:\Documents and Settings\Kathy\My Documents\test.cpp:14: error: (Each undeclared identifier is reported only once for each function it appears in.)

C:\Documents and Settings\Kathy\My Documents\test.cpp: At global scope:
C:\Documents and Settings\Kathy\My Documents\test.cpp:18: error: expected `)' before "n"
C:\Documents and Settings\Kathy\My Documents\test.cpp:18: error: expected `,' or `;' before "n"

Execution terminated



#include<iostream>
class Employee
{
      public:
            string name;
            double salary;

            Employee();
            Employee(string n, double s);
};

Employee::Employee()
{
    name = "";
    salary = 0.0;
}

Employee::Employee(string n, double s)
{
  name = n;
  salary = s;
}

int main()
{
      system("pause");
      return 0;
}
0
 
mustish1Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.