C++ Answers

Questions answered by Experts: 9 913

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Write a C++ program to implement a three-player dice game with the following rules:

1. Begin with Player A and roll two dice: dice d1 and dice d2.

2. If the sum of the two dice is odd, then accumulate it as the score of Player A. If even, then the score is 0.

3. Then roll d1 and d2 for Player B.

4. If the sum of the two dice is odd, then accumulate it as the score of Player B. If even, then the score is 0.

5. Then roll d1 and d2 for Player C.

6. If the sum of the two dice is odd, then accumulate it as the score of Player C. If even, then the score is 0.

7. Repeat steps 1 to 6 for n rounds, where n is a positive integer provided as input by the user.


  1. Ask the user to input three values (1) Start, (2) Step and (3) Stop
  2. Use any looping statement you learned and output the series of numbers based on the start, step and stop values, see sample output below.

Input Output

Start: 0 0, 2, 4, 6, 8

Step: 2 count: 4

Stop: 8 sum: 20


Start: 2 2, 6, 10

Step: 4 count: 3

Stop: 12 sum: 18


Start: 1 1, 2, 3, 4, 5

Step: 1 count: 5

Stop: 5 sum: 15


This should be what I'll see when I run the program like this below:

SCREEN LAYOUT / DESIGN


START: 0

STEP: 2

STOP: 10


SSS: 0 2 4 6 8 10

COUNT: 6

SUM: 30


Try Another [Y/N]:Y





Write a program that keeps asking a user to guess a number until they get the secret number. Indicate to the user if the guess is too low or high and also indicate how many guesses were taken to get the secret number. Assume that that the secret number is 37. Use the following sample run as a reference to test your results:

Question 3 [15 Marks) Write a C++ code to read a line of string as an input and do the following operations. Do proper input o validation to your input. 1) Capitalize first and last character of each word in the given string. [3 Marks] ii) Delete a word from the given string. Popup a message if the string is empty. [5 Marks) Page 3 of 6 iii) Add a word in the middle of the given string. Capitalize the new word if it already exists. [5 Marks] For proper input validation [2 marks]






1.      Create a function that would help you compute the average expense of car fueling in a month. It would take as an input number of times in a month that you have refueled. Create a dynamic array of the given size. Then you would be required to input that may times the amount used to refuel and store values in this dynamic array. Now compute the .using in c++.

a.      average of these cost

b.      most expensive refueling

c.      Least expensive refueling.

2.      Overload the function from 1 to read the number of entries in a file. Create a dynamic array of the given size. Then you would be required to input that may times the amount used to refuel and store values in this dynamic array. Now compute the

a.      average of these cost

b.      most expensive refueling

c.      Least expensive refueling.

3.      Write back results from 1 in the file “manual_input.txt”

4.      Write back results from 2 in the file “automated_input.txt”




write a program which loads (from keyboard)variables of four basic types

1.integer number(preferably short)


You are required to build a system that can generate a random winning scenario for the T20 cricket world cup. There12 teams which will play knock-out matches in the first round. losing team is out and the winning team moves on. From the twelve teams, six winning teams will play another knock-out match. From these six teams, three winning teams will play against each other on the round robin basis (i.e. team A plays against team B, team B plays against team C, and team C plays against team A). The top two teams from this round will move to the final match. In case all the teams win one match each at this stage, then there will be a toss to move one team to the final while the other two teams will play against each other and the winner moves to the final. The winner of the final match is champion. generate random numbers for matches and toss You are required to use if-else (if-else-if) structure to run the tournament and generate one complete winning scenario randomly.


You are required to build a class to represent the a cup of coffee. Call your class CoffeeCup. A coffee cup will have following characteristics 1. type (sting) // can be mocha, cupaccino, etc 2. temperature (float): represents the measure of temperature in degrees 3. volume (float):// the volume of coffee in the cup in ml liters 4. sugar (int):// no of teaspoons of sugar added to the coffee Provide these methods 1. parameterized constructor CoffeeCup(string t, float temp float vol, int sug) 2. Provide setters for temperature, and sugar and volume. 3. Provide getters of temperature, sugar, volume and type. 4. void heatUp(): //this method represents the process of heating the coffee, the current temperature of coffee goes up by one degree if it is below 100 and stays the same otherwise 5. void cooldown(): the process of cooling down. The temperature goes down by one degree but will not go below 0 6.


class in c++

parameterized constructor CoffeeCup(string t, float temp float vol, int sug) 

1.void heatUp(): //this method represents the process of heating the coffee, the current 

temperature of coffee goes up by one degree if it is below 100 and stays the same otherwise 

2.void cooldown(): the process of cooling down. The temperature goes down by one degree but 

will not go below 0 

3.bool isSweet():// returns true if this coffee has any amount of sugar in it and 0 if not at all 

4.bool hasMore(): //this method checks if the cup has coffee in it that a person can take a sip 

from. For the implementation assume that one sip consumes a volume of 0.3 ml. 

5.bool isEmpty(): // returns true if a person can take a sip from this cup and false otherwise 

6.bool takeASip():// this method represents the actual act of sipping.


Write a program the declares and initalises the variable myNum to the value 20.


Miss question was the ofference bene and


Now using a while loop decrease the value of myNum by 0.5 and continue to print its value as long as it remains positive (e.g. above zero).


LATEST TUTORIALS
APPROVED BY CLIENTS