Question

In: Computer Science

C++ Write a definition for a structure type for records for books. The record contains ISBN...

C++

Write a definition for a structure type for records for books. The record contains ISBN number, price, and book cover (use H for Hard cover and P for paper cover). Part of the problem is appropriate choices of type and member names. Then declare two variables of the structure.

Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.

Solutions

Expert Solution

Used, long long int for ISBN, double for price and char for Book Cover Type.

C++ program:

#include<iostream>
using namespace std;


//structure definition for Book
struct Book{
    
    //long long int data type for ISBN
    long long int ISBN;
    double price;
    char BookCover;

};


//function to get data from user
void getData(struct Book &b){

    cout<<"\nEnter the details of book: "<<endl;
    cout<<"ISBN: ";
    cin>>b.ISBN;
    cout<<"Price: ";
    cin>>b.price;
    cout<<"Book Cover Type( H for Hard cover and P for Paper cover): ";
    cin>>b.BookCover;

}

//print data stored in a structure
void printData(struct Book b){

    cout<<"\n\nBook Details\n"<<endl;
    cout<<"ISBN: "<<b.ISBN<<endl;
    cout<<"Price: "<<b.price<<endl;
    cout<<"Book Cover Type: "<<b.BookCover<<endl;
}

int main(){

    //declaring two variables of Book type
    struct Book a, b;

    //calling getData to read data from user
    getData(a);

    //printing the data of object a
    printData(a);

    getData(b);
    printData(b);

    return 0;
}

Output:

if it helps you, do upvote as it motivates us a lot!


Related Solutions

Write an ISBN Validator in C language What are ISBN? ISBN, or International Standard Book Number,...
Write an ISBN Validator in C language What are ISBN? ISBN, or International Standard Book Number, is a numeric identifier for commercially printed books. Prior to 2007, they had 10 digits, but all newly issued ISBN use 13 digits. They are used to uniquely identify a book and consist of several portions. These include the registrant group, publisher, title, and a check digit. The registrant group indicates where the publisher is located. For example a registrant group of 0 or...
In C++ Write the definition for following methods of List data structure. 5. pushFront – The...
In C++ Write the definition for following methods of List data structure. 5. pushFront – The function appends an element in the list at the front. The operation increases the number of elements in the list by one. 6. pushback - The function appends an element in the list at the end. The operation increases the number of elements in the list by one. 7.popFront - The function returns and then removes an element in the list from the front....
In C++ Write the definition for following methods of List data structure. 1. setList – The...
In C++ Write the definition for following methods of List data structure. 1. setList – The function set the value of list elements equal to a value passed as the function input. 2. getAt – The function returns an element of the list referred by its position which is given to the function as input. 3. insertAt – The function inserts a given element passed as function input in the list at the specified position also passed as second function...
Write a C program that contains a structure that uses predefined types and union. • Create...
Write a C program that contains a structure that uses predefined types and union. • Create a struct with name, age, kind (Either child, college student, or adult), and kindOfPerson (Either kid, student, or adult) • kids have a school field. Students have college and gpa. Adults have company and salary. • Create one non-dynamic struct with the content for a college student: "Bob", 20, K-State, 3.5 • Create one struct dynamically for a kid with: "Alison", 10, "Amanda Arnold...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book...
Write a c++ class definition for an abstract data type describing a bookstore inventory. Each book has the following attributes: Book Title (character string); Book Author (character string); Book Price (Floating point number having two decimal places); Count of books on hand (int); The member functions are as follows: A constructor that is used to initialize all four elements of the structure to values inputted by the user; A function that displays in a readable tabular form the contents of...
PLEASE USE ASSEMBLY LANGUAGE The database students.db contains student records. Each record contains a name (30B...
PLEASE USE ASSEMBLY LANGUAGE The database students.db contains student records. Each record contains a name (30B ASCII), student ID (9B ASCII), 3 grades out of 100 (3B integers), and a letter grade (1B ASCII). For the file students.db described above, assume all records are ordered alphabetically based on the name field. A record for a new student has been entered and stored in memory. Determine how to insert the new record into the database (Hint: use string compares to determine...
Write a C program for a library automation which gets the ISBN number, name, author and...
Write a C program for a library automation which gets the ISBN number, name, author and publication year of the books in the library. The status will be filled by the program as follows: if publication year before 1985 the status is reference else status is available. The information about the books should be stored inside a linked list. The program should have a menu and the user inserts, displays, and deletes the elements from the menu by selecting options....
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName,...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName, lastName, startYear. recordID is an integer. In testRecord, first create a record (record1) using “normal” pointers. Set the values to 1001, Fred, Flintstone, 1995 In testRecord, create a new record (record2) using a unique smart pointer. Set the values to 1002, Barney, Rubble, 2000 Create a function (or functions) that will print the records to any output stream. Since the print function does not...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes...
Programming in C (not C++) Write the function definition for a function called CompareNum that takes one doyble argument called "num". The function will declare, ask, and get another double from the user. Compare the double entered by the user to "num" and return a 0 if they are the same, a -1 num is less than the double entered by the user and 1 if it is greater.
Write the following task in C++1) Write the definition of a function numOccurrences thatsearches...
Write the following task in C++1) Write the definition of a function numOccurrences that searches for a character in a character array and returns the number of times it occurs in the array. The function has three formal parameters: a char array array, an int variable arraySize representing the size of the array, and a character variable letter representing the character to be searched for in the array.2) Assume the array numbers is an int array of size 10 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT