Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6839567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:44:03+00:00 2026-05-26T23:44:03+00:00

Just beginning to learn about structs, I thought I understood how they work, using

  • 0

Just beginning to learn about structs, I thought I understood how they work, using the dot operator to access a member of an object, but i clearly don’t as the readEmployeeRecord function below doesn’t work at all. How should i be doing this? (the code is short and self explantory)

Many thanks for taking the time to further explain structs to me! Naturally I tried google first but i couldn’t find an example that inputted data quite the way i wanted and wasn’t sure how i should be going about it.

#include <iostream>
#include <iomanip>

using namespace std;

//Employee type
struct Employee{
    float wage;
    char status;
    char dept[4]; //for 3letter department, last position is \0 correct?
};

//function definitions
void readEmpoyeeRecord(Employee staff);
void printEmployeeRecord(Employee staff);

int main(){

    Employee employeeA;
    readEmpoyeeRecord(employeeA);
    printEmployeeRecord(employeeA);
    return 0;
}
void readEmpoyeeRecord(Employee employee){
    cout << "Enter empolyees wage: ";
    cin >> employee.wage;
    cout << "Enter empolyees status (H or S): ";
    cin >> employee.status;
    cout << "Enter empolyees dept (ABC): ";
    cin >> employee.dept;
}
void printEmployeeRecord(Employee staff){
    cout << "Wage:     Status:     Department:" <<endl;
    cout << fixed << setprecision( 2 ) << staff.wage;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:44:04+00:00Added an answer on May 26, 2026 at 11:44 pm

    First, try searching google for “passing parameters by reference and by value”.

    You’ll learn that:

    void readEmpoyeeRecord(Employee staff);
    

    passes your variable to the function by value, meaning that a copy of your object is created and used inside the function, so your original object doesn’t get modified, but a copy.

    To get the desired result, use:

    void readEmpoyeeRecord(Employee& staff);
    

    Passing by reference means you pass that exact same object, and not a copy.

    Your code will basically work like this:

    //create new employee
    Employee employeeA;
    //call method readEmployeeRecord on a copy of employeeA
    readEmpoyeeRecord(employeeA);
    //call method printEmployeeRecord on a copy of employeeA
    printEmployeeRecord(employeeA);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just beginning to learn OpenCV and I would like to ask about how
I am new to linux, and just beginning to learn bash. I am using
I'm beginning to learn about the use of structs in C. It's challenging and
i'm just beignning to learn about structs and seperating things into different files. At
I'm just beginning to learn about the differences between how css (and html) is
I'm just beginning to learn about file compression and I've run into a bit
I'm just beginning to learn about proper releasing of objects for memory management in
I'm just beginning to learn Java and I have been very frustrated about learning
I am just beginning to learn about accessbility specifically in relation to JAWS -
We are just beginning to learn and evaluate Mercurial, due to an increasing number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.