Question

"Function does not take 0 arguments". I keep getting this error for my last line of...

"Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl;

I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string.

#include<iostream>
#include<string>

using namespace std;

class Employee {
   int salary;
   string firstName;
   string lastName;
public:
   Employee(string firstName, string lastName, int salary)
   {
       setfirstName(firstName);
       setlastName(lastName);
       setsalary(salary);
   }

   void setfirstName(string name1) {
       firstName = name1;
   }

   string getfirstName(string name1) {
       return firstName;
   }

   void setlastName(string name2) {
       lastName = name2;
   }

   string getlastName(string name2) {
       return lastName;
   }

   int setsalary(int b) {
       if (salary < 0) {
           salary = 0;
       }
       else
       salary = b;
   }

   int getsalary() {
       return salary*12;
   }

};

void main()
{
   Employee employee1("Mike", "Johnson", 500);

       cout << "First Name: " << employee1.getfirstName() << endl;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE

#include<iostream>
#include<string>

using namespace std;

class Employee {
int salary;
string firstName;
string lastName;
public:
Employee(string firstName, string lastName, int salary)
{
setfirstName(firstName);
setlastName(lastName);
setsalary(salary);
}

void setfirstName(string name1) {
firstName = name1;
}

string getfirstName() {
return firstName;
}

void setlastName(string name2) {
lastName = name2;
}

string getlastName() {
return lastName;
}

int setsalary(int b) {
if (salary < 0) {
salary = 0;
}
else
salary = b;
}

int getsalary() {
return salary*12;
}

};

int main()
{
Employee employee1("Mike", "Johnson", 500);
cout << "First Name: " << employee1.getfirstName() << endl;
   return 0;
}

OUTPUT SCREENSHOT

Here you in the function

string getfirstName(string name1) {
       return firstName;
   }

you pass one argument string no need to pass that. This gives you error otherwise all good, Constructor works fine .

please give a upvote if u feel helpful.

Add a comment
Know the answer?
Add Answer to:
"Function does not take 0 arguments". I keep getting this error for my last line of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

  • using C++ language!! please help me out with this homework In this exercise, you will have...

    using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • Main:This is my code for my main, employee.h, and node.h files. I'm trying to rewrite my...

    Main:This is my code for my main, employee.h, and node.h files. I'm trying to rewrite my main to use the node.h to were it is a singly linked list and am failing. Can someone show me how to actually obtain this? #include <iostream> #include <string> #include <stdlib.h> #include <cstdlib> #include <ctime> #include "Employee.h" #include "Node.h" using namespace std; void deleteList(Node** head_ref)  {   Node* current = *head_ref;   Node* next;      while (current != NULL)  {       next = current->next;       free(current);       current = next;   }  ...

  • Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string...

    Create the Employee class: The Employee class has three attributes: private: string firstName; string lastName; string SSN; The Employee class has ▪ a no-arg constructor (a no-arg contructor is a contructor with an empty parameter list): In this no-arg constructor, use “unknown” to initialize all private attributes. ▪ a constructor with parameters for each of the attributes ▪ getter and setter methods for each of the private attributes ▪ a method getFullName() that returns the last name, followed by a...

  • My main() file does not call to the class created in a .hpp file. It comes...

    My main() file does not call to the class created in a .hpp file. It comes out with the error "undefined reference to "___" const. I want to solve this by only changing the main() .cpp file, not the .hpp file. .cpp file .hpp file Thank you! include <iostream> include <string> tinclude "CourseMember.hpp using namespace std int main0 CourseMember CourseMember(90, "Jeff", "Goldblum"): // initializing the constructor cout<< "Member ID is <<CourseMember.getID) << endl; 1/ calling getID) accessor cout <<"First Name...

  • This is c++ programming and here is my code. I am getting an exception thrown on...

    This is c++ programming and here is my code. I am getting an exception thrown on the destructor for permanentworker. Can you tell me why I am getting this exception? #include <iostream> #pragma warning(disable:4996) class PermanentWorker { private:    char *name;    int salary; public:    PermanentWorker(const char* nam, int money) : salary(money)    {        name = new char[strlen(nam) + 1];        strcpy(name, nam);    }    int getPay() const    {        return salary;   ...

  • I need help in getting the second output to show both the commission rate and the...

    I need help in getting the second output to show both the commission rate and the earnings for the String method output package CompemsationTypes; public class BasePlusCommissionEmployee extends CommissionEmployee { public void setGrossSales(double grossSales) { super.setGrossSales(grossSales); } public double getGrossSales() { return super.getGrossSales(); } public void setCommissionRate(double commissionRate) { super.setCommissionRate(commissionRate); } public double getCommissionRate() { return super.getCommissionRate(); } public String getFirstName() { return super.getFirstName(); } public String getLastName() { return super.getLastName(); } public String getSocialSecurityNumber() { return super.getSocialSecurityNumber(); } private...

  • Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...

    Here is the code from the previous three steps: #include <iostream> using namespace std; class Student { private: //class variables int ID; string firstName,lastName; public: Student(int ID,string firstName,string lastName) //constructor { this->ID=ID; this->firstName=firstName; this->lastName=lastName; } int getID() //getter method { return ID; } virtual string getType() = 0; //pure virtual function virtual void printInfo() //virtual function to print basic details of a student { cout << "Student type: " << getType() << endl; cout << "Student ID: " << ID...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT