1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mestny [16]
3 years ago
9

In this lab, you write a while loop that uses a sentinel value to control a loop in a C++ program that has been provided. You al

so write the statements that make up the body of the loop.
The source code file already contains the necessary variable declarations and output statements. Each theater patron enters a value from 0 to 4 indicating the number of stars the patron awards to the Guide’s featured movie of the week. The program executes continuously until the theater manager enters a negative number to quit. At the end of the program, you should display the average star rating for the movie.

Instructions
Ensure the source code file named MovieGuide.cpp is open in your code editor.

Write the while loop using a sentinel value to control the loop, and write the statements that make up the body of the loop. The output statements within the loop have already been written for you.

Ensure you include the calculations to compute the average rating.
Execute the program by clicking the Run button.
Input the following: 0, 3, 4, 4, 1, 1, 2, -1

Ensure the average output is correct.

Strictly use the given code
// MovieGuide.cpp - This program allows each theater patron to enter a value from 0 to 4
// indicating the number of stars that the patron awards to the Guide's featured movie of the
// week. The program executes continuously until the theater manager enters a negative number to
// quit. At the end of the program, the average star rating for the movie is displayed.

#include
#include
using namespace std;

int main()
{

// Declare and initialize variables.
double numStars; // star rating.
double averageStars; // average star rating.
double totalStars = 0; // total of star ratings.
int numPatrons = 0; // keep track of number of patrons


// This is the work done in the housekeeping() function
// Get input.
cout << "Enter rating for featured movie: ";
cin >> numStars;

// This is the work done in the detailLoop() function
// Write while loop here

// This is the work done in the endOfJob() function
cout << "Average Star Value: " << averageStars << endl;
return 0;
} // End of main()
Computers and Technology
1 answer:
SVETLANKA909090 [29]3 years ago
3 0

Following are the C++ program to calculating the average value.

Program Explanation:

  • Defining header file.
  • Defining the main method.
  • Defining three double variable "numStars,averageStars, and totalStars", and one integer variable "numPatrons".
  • After declaring a variable, an input method is used that inputs an integer variable.
  • In the next step, a while loop is declared that uses an integer variable to the check value between 0 to 4.
  • Inside the loop, it adds the integer variable value and uses a conditional statement that checks integer value equal to 0, that hold 0 value into the "averageStars".
  • In the else block it calculates the average value and prints its value.

Program:

#include <iostream>//defining header file  

#include <string>//defining header file  

using namespace std;

int main()//main method

{

double numStars,averageStars,totalStars=0; // defining a double variable

int numPatrons = 0; //defining integer variable

cout << "Enter rating for featured movie: ";//print message

cin >> numStars;//input integer variable

while(numStars >= 0 && numStars<=4)//using while loop that use integer variable to check value in between 0 to 4

{

   numPatrons++; // increasing integer variable value

   totalStars += numStars; // using totalStars that adds numStars value in it

   cout << "Enter rating for featured movie: ";//print message

   cin >> numStars;//input double value

  }

if(numPatrons == 0)//using if block that check integer value equal to 0

      averageStars = 0;//holding value into averageStars

else//else block

      averageStars = totalStars/numPatrons;//calculating averageStars value

cout << "Average Star Value: " << averageStars << endl;//print message with averageStars value

return 0;

}

Output:

Please find the attached file.

Learn more:

brainly.com/question/16665413

You might be interested in
What is the output of the following Python statements? def recurse(a): if (a == 0): print(a) else: recurse(a) recurse(0)
FrozenT [24]

Answer:

d) 0 1 1 2

The above piece of code prints the Fibonacci series.

Explanation:

def a(n):

   if n == 0:

       return 0

   elif n == 1:

       return 1

   else:

       return a(n-1)+a(n-2)

for i in range(0,4):

   print(a(i),end=" ")

5 0
3 years ago
Florescent lights tend to emit less of what color?
Olin [163]
I believe it emits more yellow, it can even be blue or green 
4 0
3 years ago
Write a function called backspaceCompare that takes two strings sl and s2 and evaluate them when both are typed into empty text
Andrej [43]

Answer:

Go to explaination for the program code

Explanation:

import java.util.Stack;

public class Lab3 {

public static void main(String[] args) {

String s1="DataStructuresIssss###Fun";

String s2="DataStructuresIszwp###Fun";

boolean ans=backspaceCompare(s1,s2);

System.out.println(ans);

/*String s1="abc##";

String s2="wc#d#";

boolean ans=backspaceCompare(s1,s2);

System.out.println(ans);*/

}

public static boolean backspaceCompare(String s1, String s2) {

Stack<Character> s1_stack=new Stack<Character>();

Stack<Character> s2_stack=new Stack<Character>();

//backspaceCount is a variable to count back space

int backspaceCount=0;

//logic is that if '#' encountered we are putting pop else push

for(int i=0;i<s1.length();i++){

if(s1.charAt(i)=='#'){

backspaceCount++;

s1_stack.pop();

}

else

{

s1_stack.push(s1.charAt(i));

}

}

//this all is for s2 string

for(int i=0;i<s2.length();i++){

if(s2.charAt(i)=='#') s2_stack.pop();

else s2_stack.push(s2.charAt(i));

}

//here is the main logic first we are adding based upon # means we pop up the string while adding the string if any # character found

//here we are checking from the end using pop condition both are not mathing then we are returning false

for(int i=0;i<s1.length()-2*backspaceCount;i++){

if(s1_stack.pop()!=s2_stack.pop()) return false;

}

return true;

}

}

6 0
3 years ago
Most general-purpose applications use a(n) ________ that displays graphical elements called icons to represent familiar objects.
kirill [66]

A general purpose application is often called a 'off-the-shelf'. It is a kind of software that one can use at home and school. Most general-purpose applications use a graphical user interface that displays graphical elements called icons to represent familiar objects.

The graphical user interface is simply defined as a type of user interface that gives users permission to interact with electronic devices via the aid of graphical icons and audio indicator such as primary notation.

  • General purpose application software is simply defined as a type of application that is used for different kind of tasks.

It is not known to be able to perform more than one function. For example, a word processor.

Learn more from

brainly.com/question/2919813

6 0
3 years ago
Reverse Word Order: Write a program that reverses the order of the words in a given sentence. This program requires reversing th
ElenaW [278]

Answer:

function reverseArray(arr) {

   if (arr.length > 1) {

      arr = [arr[arr.length-1], ...reverseArray(arr.slice(1, -1)), arr[0]]

   }

   return arr;

}

function reverseSentence(sentence) {

   let words = reverseArray( sentence.split(" ") );

   return words.join(" ");

}

console.log( reverseSentence("The quick brown fox jumps over the lazy dog's back") );

console.log( reverseSentence("one two three") );

console.log( reverseSentence("one two") );

console.log( reverseSentence("Single") );

Explanation:

This is a solution in javascript leveraging several powerful constructs in that language, such as the spread operator.

8 0
3 years ago
Other questions:
  • HELP ME PLZZ FFFAAASSSTTTT
    8·2 answers
  • What operating system type uses icons to represent programs
    9·2 answers
  • Sam's take-home pay is $743. His deductions are $25 for OASDI, $5 for Medicare, and $27 for income tax. What is his gross pay? A
    14·1 answer
  • Respecting yourself and others, educating yourself and connecting with others, and protecting yourself and others are all aspect
    11·1 answer
  • Mobile phones that function as credit cards are called _____.
    11·1 answer
  • In the ISO/IEC 27002 framework, _________________ describes the use and controls related to encryption.
    15·1 answer
  • . Create an abstract Dollar class with two integer attributes, both of which are non-public (Python programmers - it is understo
    10·1 answer
  • Compared with other PC operating systems, the Linux-based operating systems:
    13·1 answer
  • What level of system and network configuration is required for cui?
    7·1 answer
  • Petra notices that there are a number of issues with a new fiber optic connection whose status appears to be going up and down c
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!