Purchase Solution

# This C++ program reads in information about a list of books

Not what you're looking for?

The attached is a C program which reads in information about a list of books from the keyboard, stores the information in an array of structure, and finally displays it on the screen. The information about a book includes its code (an integer value) and price (a floating point value). Code 9999 serves as a sentinel value indicating the end of input. A sample input and output are shown below:
Sample Input
Code of Book ? 7731
Price of Book ? 12.89
Code of Book ? 2175
Price of Book ? 8.50
Code of Book ? 9999
Sample Output
CODE PRICE
7731 12.89
2173 8.50
In this project, you should add more functions to this program while preserving its organization. Consider the following functions:
Count the number of books that cost less than \$10.
Sort all books by Code (You may modify the selection sort function shown in Fig 2.2 on P. 31 accordingly.)
Search the list for a book given its code.
In your main program, add statements using the three functions and showing the results on the screen.
/***************************************************************/
/* Author:
/* Course No/Section:
/* Date:
/* File Name:
/* Project No:
/* Description:
/****************************************************************/
#include <stdio.h>
#define MAX 100
struct Book {
int code;
float price;
};
void loadArray (struct Book list[], int* numOfBooksPtr);
void printArray (struct Book list[], int numOfBooks);
main()
{
int numOfBooks;
struct Book list[MAX];
printArray (list, numOfBooks);
return 0;
}
void loadArray (struct Book list[], int* numOfBooksPtr)
/* loads array list with input data from keyboard */
{
int aCode;
float aPrice;
*numOfBooksPtr = 0;
printf ("Code of Book ? ");
scanf("%d", &aCode);
while ( aCode != 9999 )
{
printf ("Price of Book ? ");
scanf("%f", &aPrice);
list[*numOfBooksPtr].code = aCode;
list[*numOfBooksPtr].price = aPrice;
(*numOfBooksPtr)++;
printf ("Code of Book ? ");
scanf("%d", &aCode);
}
}
void printArray (struct Book list[], int numOfBooks)
/* display contents of array list on screen */
{
int index;
printf("nn%10s%10s", "CODE", "PRICE");
printf("n");
for (index = 0; index < numOfBooks; index++)
{
printf("%10d%10.2fn", list[index].code, list[index].price);
}
}

##### Solution Summary

The expert examines C++ program reading information about a list of books.

##### Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

##### Basic Networking Questions

This quiz consists of some basic networking questions.

##### C++ Operators

This quiz tests a student's knowledge about C++ operators.

##### Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

##### C# variables and classes

This quiz contains questions about C# classes and variables.