Question

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

//below is c++ code

2 .

#include<iostream>
using namespace std;
struct player
{
double distance;
double timeToCoverDistance;
};
int main()
{
struct player player1;
struct player player2;
cout<<"enter distance and time taken by player1"<<endl;
cin>>player1.distance>>player1.timeToCoverDistance;
cout<<"enter distance and time taken by player2"<<endl;
cin>>player2.distance>>player2.timeToCoverDistance;
if(player1.timeToCoverDistance<player2.timeToCoverDistance)
{
cout<<player1.distance <<" "<<player1.timeToCoverDistance<<endl;
}
else
{

cout<<player2.distance <<" "<<player2.timeToCoverDistance<<endl;
}

return 0;
}

3.

#include<iostream>
using namespace std;
struct incomeTax
{
double income;
double rate;
double tax;
};
int main()
{
struct incomeTax person[5];

for(int i=0;i<5;i++)
{
cout<<"enter the income and rate of person "<<i+1<<endl;
cin>>person[i].income >> person[i].rate;
person[i].tax= (person[i].income*person[i].rate)/1004;
}
for(int i=0;i<5;i++)
{
cout<<"tax of person "<<i+1<<" is "<< person[i].tax<<endl;

}


return 0;
}

4.

#include<iostream>
using namespace std;
struct order
{
int orederId;
int bookLength[100];
};
struct book
{
int bookId;
string bookName;
double price;
struct order bookOrder;
};
int main()
{
struct book books;
//here books is declared as structure of book
return 0;
}

5.

#include<iostream>
using namespace std;
struct order
{
int orederId;
int bookLength[100];
};
int main()
{
struct order orders;
cout<<"enter order id";
cin>>orders.orederId;
cout<<"enter size of book length array"<<endl;
int n;
cin>>n;
cout<<"enter the book length value"<<endl;
for(int i=0;i<n;i++)
{
cin>>orders.bookLength[i];
}
cout<<orders.orederId<<endl;
for(int i=0;i<n;i++)
{

cout<<orders.bookLength[i];
}
}

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

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

  • Use Java language to create this program Write a program that allows two players to play...

    Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...

  • Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players...

    Using C Programming: (use printf, scanf) 18. Tic-Tac-Toc Game Write a program that allows two players to play a game of tic-tac-toc. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The program should run a loop that Displays the contents of the board array Allows player 1 to select a location on the board for an X. The program should...

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

  • write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on...

    write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on a team. Team name, player name, and player position will also be input.(two dimensional array) The program should then calculate and print the individual batting average and, after all 9 players have been entered, calculate and print the team batting average. Example of inputs and Outputs... Enter the Team name: (one time entry)...

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

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

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

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

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