(12 pts) The random variable X is normally distributed and has a mean of 18 and a standard deviation of 3.9. Determine the following probabilities: a) P ( X 12.2 ) b) P ( X 20.5 ) c) P ( 17.2 X 17.8 ) d) Determine the value of x that makes this statement true: P ( X x ) = 0.0838
.
General Principles of Intellectual Property: Concepts of Intellectual Proper...
(C++)Why does this code shows a run time error - I would like some sug.docx
1. (C++)Why does this code shows a run time error ? I would like some suggestions, and
corrections.Thanks
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <iomanip>
#include <array>
#include <ctime>
#include <limits>
// <limits>:library used to define and access various properties of numerical
// data types
//(such as the maximum and minimum values)
using namespace std;
class Snack {
private:
string snackName;
double priceSnack;
int snackQuantity;
int sold;
string* transaction;
string getCurrentTime()
{
time_t t = time(0);
struct tm ts;
char buff[10];
ts = *localtime(&t);
strftime(buff, sizeof(buff), "%X", &ts);
return buff;
}
public:
Snack() { // Default constructor
snackName = "";
priceSnack = 0;
snackQuantity = 0;
sold = 0;
transaction = nullptr;
}
Snack(string name, double price, int quant)//Overload cosntructor
{
snackName = name;
priceSnack = price;
snackQuantity = quant;
transaction = new string[quant];
2. for (int i = 0; i < quant; i++)
transaction[i] = "";
}
// Creating accessor methods
void setName(string s) {
if (s.length() <= 0) {
cout << "Please enter a name" << endl;
}
else
snackName = s;
}
void setPrice(double pr) {
if (pr <= 0) {
cout << "Please enter a price greater than 0" << endl;
}
else
priceSnack = pr;
}
void setQuantity(int qt)
{
if (qt <= 0) {
cout << "Please enter number greater than 0" << endl;
}
else {
snackQuantity = qt;
transaction = new string[qt];
for (int i = 0; i < qt; i++)
transaction[i] = "";
}
}
// Creatting getters
string getName() const {
return snackName;
}
int getInStock() const {
return snackQuantity;
}
int getSold() const {
return sold;
}
double getPrice() const {
return priceSnack;
}
3. bool buyItem(double& moneyEntered) {
if (snackQuantity == 0) {
cout << "Error: item is sold-out" << endl;
return false;
}
if (moneyEntered >= priceSnack) {
moneyEntered -= priceSnack;
transaction[sold] = getCurrentTime();
snackQuantity--;
sold++;
cout << "Item has been dispensed below" << endl;
return true;
}
else if (moneyEntered < priceSnack) {
if (moneyEntered < 0) {
cout << "Please enter a number greater than 0" << endl;
}
else {
cout << "Amount is less than the price $" << priceSnack << endl;
}
return false;
}
}
~Snack() // Destructor
{
if (sold)
{
cout << "nClosing details for " << snackName << "n";
cout << "ntNumber of sold: " << priceSnack;
cout << "ntProfit Gained: " << priceSnack * snackQuantity << "nn";
for (int i = 0; i < sold; i++) {
cout << "t" << transaction[i] << endl;
}
}
delete[] transaction;
transaction = nullptr;
cout << endl;
}
};
void displayVendingMachine(const Snack[], const int);
int getQuarters();
4. void userBuyItem(Snack[], const int);
bool promptToContinue();
int main()
{
const int SNACK_MAX = 3;
Snack snack[SNACK_MAX] = { Snack(), Snack("Candy", 1.25,5), Snack("Soda",1.00,2) };
snack[0].setName("Chips");
snack[0].setPrice(1.75);
snack[0].setQuantity(3);
cout << "Welcome to the vender machine!nn";
do
{
userBuyItem(snack, SNACK_MAX);
} while (promptToContinue());
}
// Function for formatting
void displayVendingMachine(const Snack snacks[], int size) {
cout << "Welcome to the Snack Vending Machine!" << endl;
cout << setw(54) << setfill('-') << "-" << setfill(' ') << endl;
cout << setw(5) << "Item #" << setw(20) << "Item Name" << setw(13) << "Price" << setw(14)
<< "# in Stock" << endl;
cout << setw(54) << setfill('-') << "-" << setfill(' ') << endl;
for (int i = 0; i < size; i++) {
cout << setw(5) << i + 1 << setw(20) << snacks[i].getName() << setw(10) << "$"
<< fixed << setprecision(2) << snacks[i].getPrice() << setw(10) << snacks[i].getInStock();
cout << endl;
}
cout << setw(54) << setfill('-') << "-" << setfill(' ') << endl;
cout << endl;
}
// Function to validate the quarters
int getQuarters()
{
int quarter;
// Continuously prompt the user until they enter a valid input
while (true) {
cout << "Enter a number of quarters: ";
cin >> quarter;
5. // Check if the user entered an invalid input (not a positive integer)
if (cin.fail() || quarter < 1) {
cout << "Invalid input. Enter a positive integer value greater than or"
<< " equal to 1: n";
// Clear the error flags in the cin stream
cin.clear();
// Ignore any remaining characters in the input buffer
cin.ignore(numeric_limits<streamsize>::max(), 'n');
continue;
}
// If a valid input was entered, exit the loop
break;
}
return quarter;
}
void userBuyItem(Snack snack[], const int size)
{
displayVendingMachine(snack,size);
int quarter = getQuarters();
int userInput;
double money;
cout << "Amount entered: " << quarter * 0.25 << endl;
money = quarter * 0.25;
while (true)
{
cout << endl << "Enter a number between 1 and " << size <<
" to make your selection: ";
cin >> userInput;
if (cin.fail() || userInput < 1 || userInput > size)
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), 'n');
cout << "Error: enter a number between 1 and " << size << ": ";
continue;
}
break;
}
snack[userInput - 1].buyItem(money);