Question

In: Computer Science

Write a program in C++ using the following 2 Files: Book.h and Source.cpp 1.)   In Book.h,...

Write a program in C++ using the following 2 Files: Book.h and Source.cpp

1.)   In Book.h, declare a struct Book with the following variables:

- isbn:   string

- title:    string

- price: float

2.)   In main (Source.cpp), declare a Book object named: book

- Use an initialization list to initialize the object with these values:

          isbn à 13-12345-01

          title à   “Great Gatsby”

          price à 14.50

3.)   Pass the Book object to a function named: showBook

- The function display the book.

          (Note:   Objects should almost always be passed by reference)

-   The function does not return a value.

     /* OUTPUT

     Here is the book:

     ISBN: 13-12345-01

     Title:   Great Gatsby

     Price: $14.50

*/

Solutions

Expert Solution

Code:

Book.h

#ifndef BOOK_H
#define BOOK_H

#include <string> // use to declare string

// struct book
struct Book
{
   std::string isbn;
   std::string title;
   float price;
};

#endif

Source.cpp

#include <iostream>
#include <iomanip>
#include <string>

#include "Book.h"

using namespace std;


// function to show book details
void showBook(struct Book *book)
{
   cout << "Here is the book:" << endl;
   cout << "ISBN: " << book->isbn << endl;
   cout << "Title: " << book->title << endl;
   // price is declared upto two decimal places
   cout << "Price: $" << setprecision(2) << fixed << book->price << endl;
}


int main()
{
   // book object declared using initilizaiton list
   struct Book myBook = {"13-12345-01", "Great Gatsby", 14.50};

   // passing above book object by reference to print it's details
   showBook(&myBook);

   return 0;
}

OUTPUT:


Related Solutions

C++ Write a program with the following elements: in main() -opens the 2 files provided for...
C++ Write a program with the following elements: in main() -opens the 2 files provided for input (Lab_HW9_2Merge1.txt and Lab_HW9_2Merge2.txt) -calls a global function to determine how many lines are in each file -creates 2 arrays of the proper size -calls a global function to read the file and populate the array (call this function twice, once for each file/array) -calls a global function to write out the 'merged' results of the 2 arrays *if there are multiple entries for...
C++ Write a program with the following elements: in main() -opens the 2 files provided for...
C++ Write a program with the following elements: in main() -opens the 2 files provided for input (Lab_HW9_2Merge1.txt and Lab_HW9_2Merge2.txt) -calls a global function to determine how many lines are in each file -creates 2 arrays of the proper size -calls a global function to read the file and populate the array (call this function twice, once for each file/array) -calls a global function to write out the 'merged' results of the 2 arrays *if there are multiple entries for...
C++ Write a program with the following elements: in main() -opens the 2 files provided for...
C++ Write a program with the following elements: in main() -opens the 2 files provided for input (Lab_HW9_2Merge1.txt and Lab_HW9_2Merge2.txt) -calls a global function to determine how many lines are in each file -creates 2 arrays of the proper size -calls a global function to read the file and populate the array (call this function twice, once for each file/array) -calls a global function to write out the 'merged' results of the 2 arrays *if there are multiple entries for...
using C++ 24. Using Files—Total and Average Rainfall Write a program that reads in from a...
using C++ 24. Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average...
Question 1: Write a program in C++ using multi filing which means 3 files ( main...
Question 1: Write a program in C++ using multi filing which means 3 files ( main file, header file, and functions file) and attached screenshots as well. Attempt the Question completely which contain a and b parts a) Write a program that takes a number from the user and checks whether the number entered validates the given format: “0322-5441576”, xxxx-xxxxxxx where “x” implies the digits only and first two digits are 0 and 3 respectively. The program also identifies the...
C++ Goals: Write a program that works with binary files. Write a program that writes and...
C++ Goals: Write a program that works with binary files. Write a program that writes and reads arrays to and from binary files. Gain further experience with functions. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of file, a pointer to an int array, and the size of the array. The function should open the specified file in binary made, write the contents into the array, and then close the file. write another...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Multiples of 2 and 3: write a c++ program Using a while loop, write a program...
Multiples of 2 and 3: write a c++ program Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below.
Using files, Write a Java program to read 2 tutorials group of student id, assignment mark...
Using files, Write a Java program to read 2 tutorials group of student id, assignment mark (30), lab test mark(20) from 2 input files namely group1.txt and group 2.txt. Your program will calculate the total course work marks and write in to 3 output files with the following conditions: if the total course work marks are more than 40 out 50 write in to LIST1.TXT if the total course work marks are between 30 to 40 then write in to...
Write a program in C that declares the following array: int. array[] = { 1, 2,...
Write a program in C that declares the following array: int. array[] = { 1, 2, 4, 8, 16, 32 } Then write some code that accepts a number between 0 and 5 from the user and stores it in a variable called "index". Write some code that retrieves the item specified by the index, like this: int item = array[index]; Then write code that outputs the corresponding array entry based on the number the user entered. Example output: The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT