Question

In: Computer Science

Read inputs from console and store in Structure Given a structure of type “struct book” (shown...

Read inputs from console and store in Structure Given a structure of type “struct book” (shown below), read input into struct book from a console. struct book { char name[50]; char author[50] ; float price; }; Write a function: struct book solution() that reads name, author and price into “struct book”. A function return structure variable. Input C Programming: A Modern Approach K.N.King 50.45 where, First line of input represents book name. Second line of input represents book author. Third line of input represents book price. Output Name: C Programming: A Modern Approach Author: K.N.King Price: 50.45 Assume that, “struct book” is already declared. Please do not use the Get function. When used and compiled there is an error stating that it is dangerous to use and that it shouldn't be used. It won't complete the output in our system bc of the error. Thank you.

Given code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define BUFFERSIZE 2
struct book
{
char name[50];
char author[50] ;
float price;
};

struct book solution()
{
//Write your code here
}

int main()
{
struct book b;
b = solution();
printf("Name=%s\nAuthor=%s\nPrice=%.2f",b.name,b.author,b.price);
return 0;
}

Solutions

Expert Solution

Here is the code : -

Code in text format : -

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define BUFFERSIZE 2
struct book
{
char name[50];
char author[50] ;
float price;
};

struct book solution()
{
char name[50], author[50];
float price;
printf("Enter book name-> ");
gets(name);
printf("Enter author name-> ");
gets(author);
printf("Enter book's price-> ");
scanf("%f", &price);
struct book temp;
for (int i = 0; i < 50; ++i)
{
temp.name[i]=name[i];
temp.author[i]=author[i];
}
temp.price=price;
return temp;
}

int main()
{
struct book b;
b = solution();
printf("Name=%s\nAuthor=%s\nPrice=%.2f",b.name,b.author,b.price);
return 0;
}


Related Solutions

Function Name: medievalFootball​ Inputs: 1. (struct​ ​) A 1xN structure representing the "field" and the players...
Function Name: medievalFootball​ Inputs: 1. (struct​ ​) A 1xN structure representing the "field" and the players on it Outputs: 1. (char​ ​) A short sentence describing what happened. Topics: (​ structures​ ​), (conditionals)​ ​, (iteration​ ​), (cell arrays​ ​) Background: As you are backpacking through Europe during your "life​ changing study abroad experience​", you stop in a small town for a bite to eat and hear about an interesting local tradition similar to a game of football. Only it's not...
QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;...
QUESTION 60 Given the following Product structure: struct Product {     string name;     double price;     int quantity;     bool equals(const Product&); }; how would you define the equals function so two products are equal if their names and prices are equal? a. bool equals(const Product& to_compare) {     return (name == to_compare.name && price == to_compare.price); } b. bool Product::equals(const Product& to_compare) {     return (name == to_compare.name || price == to_compare.price); } c. bool equals(const Product& to_compare)...
C++ programming Complete the code to input and store all the information in the structure Book:...
C++ programming Complete the code to input and store all the information in the structure Book: title, author, year and pages. Complete the function print() with arguments and code to print a Book variable in the following format: Book title: <title> Book author: <name> Published in <year> Number of pages: <pages> #include <iostream> using namespace std; struct Book { string title; string author; string year; int pages; }; void print(/*arguments*/) { //Complete function } int main() { //Declare structure variable...
Hello, Modify the grade book program from Assessment 3 to use a custom struct to hold...
Hello, Modify the grade book program from Assessment 3 to use a custom struct to hold the student's ID number and the percentage score for each item in the grade book. The program should accept the entry of ID numbers and percentage grades (0–100) until the user signals that he or she is done entering grades. The program should then print out the ID numbers and grades entered by the user, sorted by ID number. Again, be sure to format...
How to read the given structure from a random CSV file separated by commas(which contains no...
How to read the given structure from a random CSV file separated by commas(which contains no headers only the values of the contents of the structure) and then insert in a binary search tree using one of the structure contents as a key i.e. datetime and handle duplicates in binary search tree by implementing link_list.Please develop a C code for this. struct data{ char biker_id[200]; char distance_bike_travelled[200]; char datetime[200]; char count_tripr[200]; }
PLease use c++ Write a checkbook balancing program. The program will read in, from the console,...
PLease use c++ Write a checkbook balancing program. The program will read in, from the console, the following for all checks that were not cashed as of the last time you balanced your checkbook: the number of each check (int), the amount of the check (double), and whether or not it has been cashed (1 or 0, boolean in the array). Use an array with the class as the type. The class should be a class for a check. There...
read the chapter on Functionalism in psychology from the book (an introduction to the history of...
read the chapter on Functionalism in psychology from the book (an introduction to the history of psychology), You need to choose 8 points from the chapter which are important. write Which are those and why they are important.
language c++(Data structure) You have to read a file and store a data in character array...
language c++(Data structure) You have to read a file and store a data in character array ( you cant initialize a character array, you have to code generically) code must be generic u must read a file onece u cant use built in function etc string, code in classes if u initialized a char array or ur code doesn't run i will dislike and report u you can use link list to store data
The capital structure of Orange Tradings (given in terms of both book value and market value)...
The capital structure of Orange Tradings (given in terms of both book value and market value) is as follows Bonds Preferred stock Common equityTotals Book value $15,000,000 $2,000,000 $9,000,000$26,000,000 Market value $13,000,000 $2,500,000 $18,500,000$34,000,000 After-tax cost 7.0% 9.0% 14.0% a) What is the weighted average cost of capital using both Book Value and Market Value calculations for Orange Tradings? (15Marks) b) Orange Tradings is considering a project that costs N$320,000 where they would make a return of N$51,000. Would you...
The manager of a book store at City College purchases T-shirts from a vendor at a...
The manager of a book store at City College purchases T-shirts from a vendor at a cost of $25 per shirt. The bookstore incurs an ordering cost of $100 per order, and the annual holding cost is 18% of the purchase cost of a T-shirt. The store manager estimates that the demand for T-shirts for the upcoming year will be 1,800 shirts. The store operates 50 weeks per year, five days per week. The vendor is willing to offer quantity...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT