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

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are four parts for one code, all are small code segments for one question. public class StudentTest { public static void main(String[] args){ // Part Time Student Test Student ft1 = new PartTimeStudent("George", "Bush", "123-12-5678", 1, 2 ); System.out.println(ft1); Student ft2 = new PartTimeStudent("Abraham", "Lincoln", "001-90-5323", 6, 22 ); System.out.println(ft2); // Full Time Student Test Student pt1 = new FullTimeStudent("Nikola", "Tesla", "442-00-0998", 8, 26...

  • 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...

  • JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you...

    JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...

  • 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;   ...

  • 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...

  • 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...

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