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

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
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 ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are...
WRITE ONLY THE TO DO'S   in FINAL program IN C++ (necessary cpp and header files are witten below) "KINGSOM.h " program below: #ifndef WESTEROS_kINGDOM_H_INCLUDED #define WESTEROS_KINGDOM_H_INCLUDED #include <iostream> namespace westeros { class Kingdom{         public:                 char m_name[32];                 int m_population; };         void display(Kingdom&);                      } #endif } Kingdom.cpp Program below: #include <iostream> #include "kingdom.h" using namespace std; namespace westeros {         void display(Kingdom& pKingdom) {                 cout << pKingdom.m_name << ", population " << pKingdom.m_population << endl;                                                               FINAL:...
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...
((by C++ ))Write a program that will reverse the content of a Queue using the following...
((by C++ ))Write a program that will reverse the content of a Queue using the following standard queue operations. enqueue(x) : Add an item x to rear of queue. dequeue() : Remove an item from front of queue. empty() : Checks if a queue is empty or not. For reversing the queue one approach could be to store the elements of the queue in a temporary data structure in a manner such that if we re-insert the elements in the...
Write a program in c++ that merges numbers from two files and writes all the numbers...
Write a program in c++ that merges numbers from two files and writes all the numbers into a third file in ascending order. Each input file contains a list of 50 sorted double floating-point numbers from the smallest to largest. After the program is run, the output file will contain all 100 numbers between in the two input files, also sorted from smallest to largest. Format the output into two columns – the first column contains the numbers 1-100, and...
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT