0% found this document useful (0 votes)
52 views

CS 1 Assignment #6

This document contains the code for a C++ program that: 1) Prompts the user to enter a wholesale cost and markup percentage, then calculates and displays the retail price. 2) Includes functions to validate user input and calculate the retail price. 3) Runs validation checks to ensure numbers entered are above 0.

Uploaded by

Mukul Natarajan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

CS 1 Assignment #6

This document contains the code for a C++ program that: 1) Prompts the user to enter a wholesale cost and markup percentage, then calculates and displays the retail price. 2) Includes functions to validate user input and calculate the retail price. 3) Runs validation checks to ensure numbers entered are above 0.

Uploaded by

Mukul Natarajan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

CS-1 Lab-6 Due: March-12 at 11:59 PM

Code:
#include <iostream>
#include <iomanip>

using namespace std;

double calculateRetail(double, double);


double inputValidate(double);

int main()
{
double wholesale_cost,
markup_percent,
retail_price;

cout << "Enter wholesale cost: ";


wholesale_cost = inputValidate(wholesale_cost);

cout << "Enter it's markup percentage: ";


markup_percent = inputValidate(markup_percent) * .01;

retail_price = calculateRetail(wholesale_cost, markup_percent);

cout << "Markup percentage = %"


<< (markup_percent / .01)
<< endl;

cout << setprecision(2) << fixed


<< "Wholesale cost = $"
<< wholesale_cost
<< endl

<< "Retail price = $"


<< retail_price
<< endl;

return 0;
}

double calculateRetail(double num1, double num2)


{
return (num1 * num2) + num1;
}

double inputValidate(double num)


{
while(!(cin >> num) || (num < 0))
{
cout << "Error. An integer above 0 must be entered: ";
cin.clear();
cin.ignore(123, '\n');
}
return num;
}
Result:
code:
#include <iostream>
#include <cmath>
using namespace std;

float FallingDistance(double);

int d;

int main (){


  double t;
  int i = 1;
  while (i<=10){
    cout << "Enter Time: \n";
    cin >> t;
    d = FallingDistance(t);
    cout << "Distance: " << d << "\n";
    i++;
  }

float FallingDistance (double time){


  float g = 9.8;
  return (0.5) * g * pow(time, 2);
}
Result:
code:
#include <iostream>
using namespace std;

double celsius(double);

int main()
{
const int MIN_TEMP = 0,
MAX_TEMP = 20;
double C;

cout << "-----------------------------------|\n";


cout << "Fahrenheit | Celsius\n";
cout << "-----------------------------------|\n";

for (int F = MIN_TEMP; F <= MAX_TEMP; F++)


{
C = celsius(F);
cout << F << " ";
cout << C << endl;

return 0;
}
double celsius(double R)
{
return (5.0/9.0) * (R - 32.0);
}
Result:

code:
#include <iostream>
#include <cstdlib> // For rand() and srand()
#include <ctime> // For time() function
using namespace std;
void coinToss();
int inputValidate(int);

int main()
{
int choice;
unsigned seed = time(0);
srand(seed);

cout << "How many times should the coin be tossed? ";
choice = inputValidate(choice);

for (int i = 0; i < choice; i++)


coinToss();

return 0;
}

int inputValidate(int num)


{
while(!(cin >> num) || num < 0)
{
cout << "Error. An integer above 0 must be entered: ";
cin.clear();
}
return num;
}

void coinToss()
{
const int MIN_VALUE = 1,
MAX_VALUE = 2;

int coin;

coin = (rand() % (MAX_VALUE - MIN_VALUE + 1)) + MIN_VALUE;

cout << (coin == MIN_VALUE ? "Heads" : "Tails") << endl;


}
Result:

You might also like