Question

Structures in C++ :- 1. Write a program that declares a structure to store the code...

Structures in C++ :-

1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary.

2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner.

3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income and tax rate of five persons and then displays the tax payable.

4. Write a program that declares a structure Book to store bookid, book name and price. It declares another structure order that contains order id and an array of book of length 5. The program should define a variable of type order and input the values from the user. The program finally displays the value.

Note :- Need proper Indent and Output.

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

Note: According to HOMEWORKLIB POLICY we can't answer more than 1 question, please ask other problems as a separate question. I hope you understand. Thank You

If you have any problem with the code feel free to comment. I have completed the first problem

Program

#include <iostream>

using namespace std;

//employee structure
struct Employee{
int code;
float salary;
char grade;
};

//for taking employee input
Employee takeInput(Employee emp){
cout<<"Enter Code: ";
cin>>emp.code;

cout<<"Enter Salary: $";
cin>>emp.salary;

cout<<"Enter Grade: ";
cin>>emp.grade;

return emp;
}

//finding greater salary
Employee maxSalary(Employee emp1, Employee emp2){
if(emp1.salary > emp2.salary)
return emp1;
return emp2;
}


int main()
{
Employee emp1, emp2;

cout<<"Employee 1 Details - "<<endl;
emp1 = takeInput(emp1);

cout<<"\nEmployee 2 Details- "<<endl;
emp2 = takeInput(emp2);

Employee emp = maxSalary(emp1, emp2);

//displaying the output
cout<<"\nEmployee with greater salary-"<<endl;
cout<<"Code: "<<emp.code<<endl;
cout<<"Salary: $"<<emp.salary<<endl;
cout<<"Grade: "<<emp.grade<<endl;

return 0;
}

Output

Employee 1 Details Enter Code: 121 Enter Salary: $5000 Enter Grade: A Employee 2 Details- Enter Code: 122 Enter Salary: $5500

Add a comment
Know the answer?
Add Answer to:
Structures in C++ :- 1. Write a program that declares a structure to store the code...
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
  • Structures in C++ :- 2. Write a program that declares a structure to store the distance...

    Structures in C++ :- 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner. 3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income...

  • Submit two C++ files: 1. Write a C++ program that declares an array alpha of 50...

    Submit two C++ files: 1. Write a C++ program that declares an array alpha of 50 components of type double. Initialize the array so that the first 25 components are equal to the square of the index variable, and the last 25 components are equal to three times the index variable. Output the array so that 10 elements per line are printed. 2. Write a program that prompts the user to input a string and outputs the string in uppercase...

  • Pointer tasks: ( In C++ ) 1. Write a program to store the address of a...

    Pointer tasks: ( In C++ ) 1. Write a program to store the address of a character variable and a float variable. • Print the address of both variables. • Print the values of variable using dereference operator. • Add 2 in float value using pointer. • Print address of character variable using reference operator. 2. Write a program that takes 5 elements in an array and print them in reverse order using pointers. 3. Write to program that takes...

  • Inventory Program (C++) Write a program that uses a structure to store the following inventory data...

    Inventory Program (C++) Write a program that uses a structure to store the following inventory data in a file: - Item Description -Quantity on Hand -Wholesale cost -Retail cost -Date Added to Inventory The program should have a menu that allows the user to perform the following tasks: -Add new records to file -Display any record in the file -Change any record in the file Input Validation: The program should not accept quantities, or wholesale or retail costs, less than...

  • 8. (15 marks) Write a complete C program, which uses an array of structures and two...

    8. (15 marks) Write a complete C program, which uses an array of structures and two user defined functions. The program deals with a library database. The program will ask the user to input required information about each book and store it in a structure in a user defined function called get info. The second user defined function display_info will display database information on the screen. The output should look as follows: Book Title Book ld 123456 C Programming 10...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • Write a C++ program that defines a structure called StudentInfo for records consisting of a student’s...

    Write a C++ program that defines a structure called StudentInfo for records consisting of a student’s ID, age, final grade for math, final grade for reading, and final grade for music. Define an array of such records to hold up to eight students’ records that the user input students’ information from the keyboard. Then compute and print out the average of their math grades and average of reading, and each student’s average grade of math, reading and music .

  • (C++) Write a program that declares a struct to store the data of a football player...

    (C++) Write a program that declares a struct to store the data of a football player (player’s name, player’s position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards). Declare an array of 10 components to store the data of 10 football players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of...

  • Write a program (C++) that shows Game sales. The program should use a structure to store...

    Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program...

  • In this assignment, you will write one (1) medium size C program. The program needs to...

    In this assignment, you will write one (1) medium size C program. The program needs to be structured using multiple functions, i.e., you are required to organize your code into distinct logical units. The following set of instructions provide the specific requirements for the program. Make sure to test thoroughly before submitting. Write   a   program,   named   program1.c,   that   reads   and   processes   employee   records   (data   about   an   employee).   Each   employee   record   must   be   stored   using   a   struct   that   contains   the   following  ...

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