Question

Using Structs within Structs Refer to the Structure on page 624 in the 7th Edition of...

Using Structs within Structs

Refer to the Structure on page 624 in the 7th Edition of the Malik Textbook (link is on this site) which defines EmployeeType as a struc with OTHER structs as its members. You can also refer to p.622 in order to see how to access the information.

=======================================================================================

Design and Implement a program that will read from a file all the elements needed to fill/ INPUT DATA for the entire structure for up to- 5 Employees

OUTPUT:  All the contents of the struct.

**PLEASE DO NOT USE VOID FUNCTION IN THIS PROGRAM AND ONLY NECESSARY HEADER FILES..MAKE IT AS SIMPLE AS IT CAN BE**

NOTE:   Use #include <iomanip> to format the output of the structure.

An example of how one can access the members of a struct is on p. 626.

This should work for the number of records in the file....

MALIK TEXT BOOK LINK: https://drive.google.com/file/d/0B6viA91V5enRclVLZmxOOUwzUGc/view?ts=59d26687

**PLEASE DO NOT USE VOID FUNCTION IN THIS PROGRAM AND ONLY NECESSARY HEADER FILES..MAKE IT AS SIMPLE AS IT CAN BE**

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

ans..........................................

Copyable code:

//Include files

#include <iostream>

#include <fstream>

#include <string>

#include <cstdlib>

#include <iomanip>

using namespace std;

//Create structure

struct nameType

{

//Declare variable

string first;

//Declare variable

string last;

};

//Create structure

struct employeeType

{

//Declare variable

nameType name;

//Declare variable

int performanceRating;

//Declare variable

int pID;

//Declare variable

string dept;

//Declare variable

double salary;

};

//Declare variable

employeeType employees[25];

//Declare variable

employeeType newEmployee;

//define function

int main()

{

//Declare variable

int cnt=0;

//Declare variable

ifstream fID;

//Open file

fID.open("inp.txt");

//Check condition

if(fID.is_open())

{

//Read name

while(fID>>newEmployee.name.first>>newEmployee.name.last)

{

//Read value

fID>>newEmployee.performanceRating;

//Read value

fID>>newEmployee.pID;

//Read value

fID>>newEmployee.dept;

//Read value

fID>>newEmployee.salary;

//Read value

employees[cnt] = newEmployee;

//Increment value

cnt++;

}

//Close file

fID.close();

//Print message

cout<<"Displaying Employees details:"<<endl;

//Loop

for(int kk=0;kk<cnt;kk++)

{

//Print message

cout<<setw(20)<<"NAME: "<<employees[kk].name.first<<" "<<employees[kk].name.last<<endl;

//Print rating

cout<<setw(20)<<"PERFORMANCE RATING: "<<employees[kk].performanceRating<<endl;

//Print p id

cout<<setw(20)<<"P ID: "<<employees[kk].pID<<endl;

//Print department

cout<<setw(20)<<"DEPARTMENT: "<<employees[kk].dept<<endl;

//Print salary

cout<<setw(20)<<"SALARY: "<<employees[kk].salary<<endl;

//Print separator

cout<<"================================================="<<endl;

}

}

//Else

else

{

//Print message

cout<<"File cannot be opened."<<endl;

}

//Return

return 0;

Add a comment
Know the answer?
Add Answer to:
Using Structs within Structs Refer to the Structure on page 624 in the 7th Edition 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
  • Programming Concepts cin/cout variables/types Functions Reference structs Task Summary: For this first Quest you I have...

    Programming Concepts cin/cout variables/types Functions Reference structs Task Summary: For this first Quest you I have set up a program in Visual Studio that will use operation between fractions. I have written a basic code example that does all the resources that you need to follow. Your job is to complete the exercises presented below in quest2.cpp. For this assignment you will learn and demonstrate how to: Work with functions use Past-by-Value and Past-by-Reference. use structs. use cin to get...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • 1. Define Structure UNIT as described in the list: ınit char codease complete the question int...

    1. Define Structure UNIT as described in the list: ınit char codease complete the question int numberOfCreditHours int semester int numberOfPreReq; pointer to number of pre-requisites eg:like char preRequisite[numberOfPreReq][10]; char* preReq int numberOfPostReq; pointer to number of post-requisites eg:like char postRequisite[numberOfPostReq] [1 0]; char* postReq NOTE: this is a BIG question and has to be asked seperately, answering only one question here. pluginfile.php/94428/mod resource/content/1/lab 6202 %20 %28file %20and%20parsing % 29.pdf Expected C++Skills to finish this activity Simple data types C++...

  • Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic...

    Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic singly linked list that can hold any data type. The interface has been specified and provided to you in a header file called mylist.h. So your job is to write mylist.c that implements each function whose prototype is included in mylist.h. Specifically, you are asked to write the following functions: struct Node *addFront(struct List *list, void *data) void traverseList(struct List *list, void (*f)(void *))...

  • Writing a program in C please help!! My file worked fine before but when I put...

    Writing a program in C please help!! My file worked fine before but when I put the functions in their own files and made a header file the diplayadj() funtion no longer works properly. It will only print the vertices instead of both the vertices and the adjacent like below. example input form commnd line file: A B B C E X C D A C The directed edges in this example are: A can go to both B and...

  • C++ code and also provide comments explaining everything Credit Card Debt The True Cost of Paying...

    C++ code and also provide comments explaining everything Credit Card Debt The True Cost of Paying Minimum Payment Write a C++ program to output the monthly payment schedule for a credit card debt, when each month nothing more is charged to the account but only the minimum payment is paid. The output stops when the balance is fully paid - remaining balance = 0. Input: Data input must be done in a separate function. Input the following: credit card balance,...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be...

    Don't attempt if you can't attempt fully, i will dislike a nd negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book tit le, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an...

  • Don't attempt if you can't attempt fully, i will dislike and negative comments would be given...

    Don't attempt if you can't attempt fully, i will dislike and negative comments would be given Please it's a request. c++ We will read a CSV files of a data dump from the GoodReads 2 web site that contains information about user-rated books (e.g., book titnle, publication year, ISBN number, average reader rating, and cover image URL). The information will be stored and some simple statistics will be calculated. Additionally, for extra credit, the program will create an HTML web...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

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