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
laila [671]
2 years ago
6

The price of an item you want to buy is given in dollars and cents. You pay for it in cash by giving the clerk d dollars and c c

ents. Write specifications for a function that computes the change, if any, that you should receive. Include a statement of purpose, the preconditions and postconditions, and a description of the arguments.
Computers and Technology
1 answer:
RSB [31]2 years ago
7 0

Answer:

Get the actual price of the item and convert it to cents, also get and convert the amount paid to cents.

subtract the actual price of the item from the paid amount ( which is in cents), if the result is greater than zero, covert the result back to dollars and output the result.

Explanation:

The program converts the actual price of the item and the amount paid to cents (where a dollar is equal to 100 cents). The variables are subtracted to get the change to be refunded, the result is converted back to dollars as the actual change to be paid.

You might be interested in
A gamer typing their name into the computer is an example of:
vova2212 [387]

user input I think I'm not sure though

3 0
2 years ago
Read 2 more answers
Adassadad saflalfaklfajfklajfalkfjalkfjalkfalkf
BlackZzzverrR [31]

Answer:

this belongs on r/ihadastroke

Explanation:

5 0
3 years ago
Read 2 more answers
write a C program that declares an integer variable called "favorite_number". The program should then prompt the user to enter t
Arturiano [62]

Answer:

// here is code in C.

// headers

#include <stdio.h>

// main function

int main(void) {

// variable declaration

int favorite_number;

 // ask user to enter favorite number

printf("enter your favorite number : ");

 // read the number

scanf("%d",&favorite_number);

 // print the message

printf("your favorite number is: %d",favorite_number);

return 0;

}

Explanation:

Declare a variable "favorite_number" of integer type.Ask user to enter favorite number and assign it to favorite_number.Then print the message which include the favorite number.

Output:

enter your favorite number : 77

your favorite number is: 77

4 0
3 years ago
Write a loop that sets each vector element to the sum of itself and the next element, except for the last element which stays th
Gekata [30.6K]

Answer:

Add the following lines of code to the already existing code segment

<em>for (i = 0; i < SCORES_SIZE-1; ++i) { </em>

<em>        bonusScores.at(i) = bonusScores.at(i) + bonusScores.at(i+1);</em>

<em>  }</em>

Explanation:

To do the task in the question, we have to iterate through the vector from the first element i.e. element at index 0 to the second to the last element; i.e. element at last index - 1

We then add each element in this iteration with the next.

This iterates through the vector from 0 to SCORES_SIZE - 1

<em>for (i = 0; i < SCORES_SIZE-1; ++i) { </em>

<em>This adds each vector element with the next</em>

<em>        bonusScores.at(i) = bonusScores.at(i) + bonusScores.at(i+1);</em>

<em>  }</em>

The above should be added before

<em>for (i = 0; i < SCORES_SIZE; ++i) { </em>

<em>        cout << bonusScores.at(i) << " "; </em>

<em>}</em>

<em />

<em>Also, I've made other modifications to the program.</em>

  • <em>Proper import of header files</em>
  • <em>Proper declaration of vector bonusScores</em>

<em />

<em>See attachment for complete source code</em>

Download cpp
6 0
3 years ago
3. (20 points) Write a C++ recursive function that finds the maximum value in an array (or vector) of integers without using any
Luden [163]

Answer:

Following are the code to this question:

In option (i):

#include <iostream>//defining header file

using namespace std;

int findMax(int B[], int x)//defining recursive method findMax

{

if (x == 1)//defining condition when value of n==1

return B[0];//return array first element

return max(B[x-1], findMax(B, x-1)); // calling recursive method inside max method and return value

}

int main() //defining main method  

{

int B[] = {12, 24, 55, 60, 50, 30, 29};//defining array B

int x= 7;//defining integer variable and assign a value

cout << "Maximum element value of the array is: "<<findMax(B, x)<<endl;//calling method findMax and print value

return 0;

}

Output:

Maximum element value of the array is: 60

In option (ii):

\Rightarrow \ T(n) = 1 + T(n-1)\\\Rightarrow  1 + 1 + T(n-2)\\ \Rightarrow  1 + 1 + 1 + ... n \ times \\\Rightarrow  O(n) \\

Explanation:

In the above-given program a recursive method "findMax" is defined, which accepts an array "B" and an integer variable "n" in its parameter, inside the method a conditional statement is used that, checks value of x equal to 1.

  • If the above condition is true it will return the first element of the array and find the max number.
  • Inside the main method, an array B is declared that assigns some values and an integer variable is declared, that also assigns some values, in the last step print method is used that pass value in method and prints its return value.
  • In the option (ii) we calculate the Big-O notation algorithm value.
5 0
3 years ago
Other questions:
  • Copy the 10 statements as they appear below into your journal.
    6·2 answers
  • Suppose you with had two algorithms, A and B, with growth functions fa(n)=200n2 and fb(n)=2n4. If you were to do an exact analys
    13·1 answer
  • List at least three benefits of automated testing?
    13·1 answer
  • Why are ethics important in PR?
    8·1 answer
  • "What Search Network text ad component provides up to three fields of 30 characters each?"
    6·1 answer
  • What are some benefits of 3-D printing?
    9·1 answer
  • Given a scanner reference variable named input that has been associated with an input source consisting of a sequence of strings
    14·2 answers
  • What are some things all boomers say.
    12·2 answers
  • Laura is the first person in her SDLC team to detect and predict security vulnerabilities in the software. In which phase is Lau
    11·1 answer
  • The designers of a database typically begin by developing a​ __________ to construct a logical representation of the database be
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!