Question

BER PROGRAMMING CONTENT: Submission request: For each program below: supply a copy of the source code provide a screenshot of

To be done in C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, Please post one question at a time.

As per Chegg policy, I am instructed to only answer the first question, please post the remaining question as separate question.

===========================================================================

#include <iostream>

#include <iomanip>

#include <fstream>

using namespace std;

/*

This calculates the discount offered with the following rules:

- the first 5 people to use the coupon gets 50% off

- the next 5 people to use the coupon gets 25% off

- everyone after that gets 10% off

Input parameters:

origPrice - a float that represents the price before the discount

Output parameters:

Returns a float that represents the price after the discount

*/

float discount(float origPrice)

{

    float newPrice=0;

    static int people = 0; // static variable to track the people number

   

    /* Your job is to fill this function with all of the necessary code to make this work as

       described in the comments above. */

      

    if(people<5){

                newPrice = origPrice*0.5; // first 5 people get 50% off

                }else if(people<10){

                                newPrice = origPrice*0.75; // next 5 people get 25% off

                }else{

                                newPrice = origPrice*0.90; // remaining people get 10% off

                }

                people+=1;

    return(newPrice);

}

int main()

{

    ifstream infile;

    float tempPrice;

    float salePrice;

    infile.open("prices.txt");

   

    if (!infile)

    {

      cout << "Couldn't open file.\n";

      return 0;

    }

   

    cout << fixed << setprecision(2);

   

    while (infile >> tempPrice)

    {

        salePrice = discount(tempPrice);

        cout << "The initial price is: $" << tempPrice << " and the discounted price is: $" << salePrice << endl;

    }

    return 0;

}

===========================================================================

Add a comment
Know the answer?
Add Answer to:
To be done in C++ BER PROGRAMMING CONTENT: Submission request: For each program below: supply a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C Programming Assignment: Implementing a Reliable Transport Protocol Overview In this laboratory programming assignment, you...

    Using C Programming Assignment: Implementing a Reliable Transport Protocol Overview In this laboratory programming assignment, you will be writing the sending and receiving transport-level code for implementing a simple reliable data transfer protocol. There are two versions of this lab, the Alternating-Bit-Protocol version and the Go- Back-N version. This lab should be fun since your implementation will differ very little from what would be required in a real-world situation. Since you probably don't have standalone machines (with an OS that...

  • Write a software key-logger and test it while you fill out a web form or type...

    Write a software key-logger and test it while you fill out a web form or type in the contents of a document using your favorite document preparation software. You can use Java or Python to do this assignment. C and C related programming language is not allowed for this assignment. Hints: You can find a demo and API for key-logger hook in the following link for JAVA. https://github.com/kwhat/jnativehook This project can only be used to learn how to use JNI...

  • Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To...

    Intro to Programming in C – Large Program 1 – Character/ Number converter Assignment Purpose: To compile, build, and execute an interactive program with a simple loop, conditions, user defined functions and library functions from stdio.h and ctype.h. You will write a program that will convert characters to integers and integers to characters General Requirements • In your program you will change each letter entered by the user to both uppercase AND lowercase– o Use the function toupper in #include...

  • Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the...

    Intro to Programming and Logic: Python 2, Chapter 8 – Strings (so far have learned the way of a program, variables, expressions, statements, functions, interface design, conditional, recursion and iteration) Write a program that takes a string as a parameter. It will analyze the string and return True if it is a valid float number. It will return False if it is not a valid float value. Your function should return True in any of these cases: 0.17, .17, 5.27,...

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each...

    c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each of two players enters either P, R, or S. The program then announces the winner as well as the basis for determining the winner: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Draw, nobody wins”. The primary differences between this and previous two versions are described as below: (1) You MUST use a function to get the input value for the player’s...

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • Write a C++ code based this question n this assignment you will create three additional functions...

    Write a C++ code based this question n this assignment you will create three additional functions for each one of the data structures created in class. You will be provided with a header file which you will modify and a demo program for each data structure. If your functions are implemented correctly the demo programs should compile and execute correctly. Part 0 (Comments) 1. Over the course of the semester we have discussed comments for each data structure. Please add...

  • In C++ Practice Exercise #3a (Calculator) Warm-Up/Version 1 Write a program that vwill get two numbers...

    In C++ Practice Exercise #3a (Calculator) Warm-Up/Version 1 Write a program that vwill get two numbers from the user and then add them together and display the result. . Step 1: Create algorithm/pseudocode . Step 2 (Optional): Watch this video: https:/lyoutu.beyjucjusHSgg Step 3: Code program Submit: . Algorithm/Pseudocode in a separate file . Version 1 source file. Make sure to upload both files before hitting submit Notes: You just need . As with the other Practice Exercise, you can submit...

  • Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you...

    Programming in C with comments/steps 1. Overview The purpose of this assignment is to give you some experience with writing functions that take in arguments and return values, as well as writing a program that consists of multiple files. This assignment also requires the use of a switch statement, in addition to more practice with printf& scanf declaring variables, using loops, and using logical expressions. For this assignment, you will prompt the user in the main function to enter their...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT