Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!