Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the programs output if the input is: 1 3 Berries 6 shirt Jump to level 1 Type the program's output - 1 Jump

What is the programs output if the input is:
13 Berries
6 shirt
Jump to level 1
Type the program's output-1 Jump to level 1
Type the program's output
main.cpp:
#include "Products.h"
using namespace std;
int main(){
Products allProducts;
allProducts.InputProducts();
allProducts.PrintAfterDiscount(2);
return 0;
}
Product.h:
#ifndef PRODUCT_H
#define PRODUCT_H
#include
class Product {
public:
void SetPriceAndName(int productPrice, std::string productName);
int GetPrice() const;
std::string GetName() const;
private:
int price;
std::string name;
};
#endif
Product.cpp:
#include "Product.h"
using namespace std;
void Product::SetPriceAndName(int productPrice, string productName){
price = productPrice;
name = productName;
}
int Product::GetPrice() const {
return price;
}
string Product::GetName() const {
return name;
}
Products.h:
#ifndef PRODUCTS_H
#define PRODUCTS_H
#include
#include "Product.h"
class Products {
public:
void InputProducts();
void PrintAfterDiscount(int discountPrice);
private:
std::vector productList;
};
#endif
Products.cpp:
#include
#include "Products.h"
using namespace std;
void Products::InputProducts(){
Product currProduct;
int currPrice;
string currName;
cin >> currPrice;
while (currPrice >0){
cin >> currName;
currProduct.SetPriceAndName(currPrice, currName);
productList.push_back(currProduct);
cin >> currPrice;
}
}
void Products::PrintAfterDiscount(int discountPrice){
unsigned int i;
int currDiscountPrice;
for (i =0; i < productList.size(); ++i){
currDiscountPrice = productList.at(i).GetPrice()- discountPrice;
cout <<"$"<< currDiscountPrice <<""<< productList.at(i).GetName()<< endl;
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions