C ++
Modify the PetHotel code on blackboard to:
#include <iostream>
using namespace std;
int printMenu();
int enterNights();
void drawLine();
int main() {
int nights;
int total;
int menu_option;
int net_total;
//enter nights
nights = enterNights();
//print the menu and enter option and calculate total
do {
//printMenu
drawLine();
menu_option = printMenu();
if (menu_option == 1)
total = total + 5;
else if (menu_option==2)
total = total + 10;
else if (menu_option==3)
total = total + 4;
else if ((menu_option>4) || (menu_option<1))
cout<<"Invalid Option"<<endl;
} while (menu_option!=4);
//calculate the net_total
net_total = total * nights;
cout<<"Total is: $"<<net_total;
}
void drawLine() {
cout<<"***********************"<<endl;
}
int printMenu() {
int menu_option;
cout<<"Boarding prices"<<endl;
cout<<"1. Small Dog"<<endl;
cout<<"2. Big Dog"<<endl;
cout<<"3. Cat"<<endl;
cout<<"4. Quit"<<endl;
cout<<"Enter option: ";
cin>>menu_option;
return menu_option;
}
int enterNights() {
int nights;
cout<<"Enter the number of nights: ";
cin>>nights;
return nights;
}
thanks for the question.
Here is the completed code for this problem. Comments are
included, go through it, learn how things work and let me know if
you have any doubts or if you need anything to change.If you are
satisfied with the solution, please rate the answer.
Changes to the existing code are commented so that you can understand the changes.
printMenu() function renamed as getPetTotal()
===============================================================================
#include <iostream>
using namespace std;
// Modify the name of the “prinMenu” method so the it is
appropriate.
int getTotalPets();
int enterNights();
void drawLine();
int main() {
int nights;
int net_total, total;
//enter nights
nights = enterNights();
//// Modify the name of the “prinMenu” method so the it is
appropriate.
total = getTotalPets();
net_total=total*nights;
cout<<"Total is: $"<<net_total;
}
void drawLine() {
cout<<"***********************"<<endl;
}
//// Modify the name of the “prinMenu” method so the it is
appropriate.
int getTotalPets() {
int menu_option;
int total=0;
drawLine();
do {
cout<<"Boarding prices"<<endl;
cout<<"1. Small Dog"<<endl;
cout<<"2. Big Dog"<<endl;
cout<<"3. Cat"<<endl;
cout<<"4. Parrots"<<endl; //Add a 4th option for
parrots – they cost $3.
cout<<"5. Quit"<<endl;
//Add a line of stars below the menu, use the same method that is
in the code.
//This is called “code reuse.” Functions/Methods allow us to do
that.
drawLine();
cout<<"Enter option: ";
cin>>menu_option;
if (menu_option == 1)
total = total + 5;
else if (menu_option==2)
total = total + 10;
else if (menu_option==3)
total = total + 4;
else if (menu_option==4)
total = total + 3; //Add a 4th option for parrots – they cost
$3.
else if ((menu_option>5) || (menu_option<1))
cout<<"Invalid Option"<<endl;
// cout<<total<<endl;
} while (menu_option!=5);
//Modify the code so the total is calculated within the printMenu
method and returned to the main method.
return total;
}
int enterNights() {
int nights;
cout<<"Enter the number of nights: ";
cin>>nights;
return nights;
}
===============================================================================

C ++ Modify the PetHotel code on blackboard to: Add a line of stars below the...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
I need to modify my C++ code so it can get the min value of the stack code is as follows: #include <iostream> using namespace std; #define MAX_SIZE 100 class Stack { private: int S[MAX_SIZE]; int top; public: Stack() { top = -1; } void push(int x) { if (top == MAX_SIZE - 1) { cout << "Stack is Full." << endl; return; } S[++top] = x; } void pop() { if (top == -1) { cout << "Stack is...
Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...
Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...
using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...
PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...
SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){ int num1,num2; cout << "Enter two numbers "<< endl; cout << "First :"; cin >> num1; cout << "Second :"; cin >>num2; int result=num1+num2; cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result; ...
Hi I've a problem with this code. When I add more than 1 song to the list, it doesn't show the first one, only shows the latest one, when I called the function displaysong, let's say when you add 2 songs ID 1 then ID 2, it shows only ID 1. Can you fix it. Everything else is fine.. #include <iostream> #include<string> using namespace std; //class Song class Song{ private: int songID; string title; string artist; string album; int year; public:...
Help me solve this in C++ Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. You can prepare a class if you wish but it is not required. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max...
C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...