Reference no: EM13938628
Declare x as float
Declare y as integer
Declare i as integer
Declare result as float
Input x // can be any float
Input y // has to be a positive integer
Set result = 1 // initial value
For i = 1 to y
result = result * x
End for
Output result
Convert this pseudocode into a C++ program. Note the restrictions on x and y: x can be any kind of float (including negatives), whereas y should only be an integer that is greater than or equal to 0 (0 is allowed).
Use the following template for your program and remember to maintain all the blank lines, spaces, and general alignment.
Then replace the areas that have been highlighted in yellow with your code. Do not change any of the other code.
Code Template for Exercise 3
/******************************************************/
/* File: Programming Project */
/* */
/* Created by: Mireille Bikim */
/* Date: April 13, 2006 */
/* */
/* flow control statements and functions */
/* */
/* Inputs: (keyboard) */
/* 1. One integer exponent (y), y >= 0 */
/* 2. One float number (x) */
/* */
/* Output: */
/* Print x^y as a float, on the screen */
/* */
/* Algorithm: repeatedly multiply x by itself, y */
/* times */
/* */
/******************************************************/
#include <iostream>
using namespace std ;
int main()
{
Write code to declare all the variables.
// read in the two numbers
cout << endl ;
cout << "Enter number to be raised to power(float) : ";
cin >> y ;
cout << "Enter the exponent (positive integer) : " ;
cin >> x ;
Initialize any variables that need to be initialized.
for ( )
{
Write the code for the for-loop initializations and the for-loop body. Carefully study and compare the pseudocode and C++ for loops in the commentary.
}
// display the result
cout << endl ;
cout << "The value of" << x << " to power " << y
<< " is : " << result << endl ;
return (0); // terminate with success
}
Test Plan for Exercise 3
Test your code on the following. See if you get the expected answer.
x y Expected answer
2 3 8
2 0 1
2 1 2
2 8 256
8 2 64
3 3 27
5 5 3,125
Now test your code with the following. You may need to use a calculator to check your answers.
x y Expected answer
2 12
-3.5 4
63.5 0
5.6 4
What is the dbm of 50 mw
: On the lower UNII-1 band (i.e., 5.150-5.250 GHz with 100 MHz channels), the maximum output power of the intentional radiator (IR) allowed by the FCC is 50 mW. The IR is also referred to as a wireless transmitter. Click in the watts box and type 0.05 ..
|
Emerging decision support environments
: Development and acquisition approaches for emerging decision support environments
|
The approximate yield to maturity
: Mesquite Corporation has a bond outstanding with a $80 annual interest payment, a market price of $850, and a maturity date in ten years. Please find
|
What occurs when depolarization wave travels by myocardium
: The sequence of depolarization of the heart chambers, as reflected by EKG, is/are? Which occurs when a depolarization wave travels through the myocardium?
|
Write the code for the for-loop initializations
: Write the code for the for-loop initializations and the for-loop body. Carefully study and compare the pseudocode and C++ for loops in the commentary.
|
Principles of project management
: Explain the principles of project management with particular emphasis on:
|
Digital forensics best practices and criminal justice
: Provide two examples of how being familiar with and following digital forensics best practices And criminal justice would benefit you, even if you worked in a non-criminal justice digital forensics position. please provide your answer at least a para..
|
Why is money so important in elections
: Please respond to the following in 3-4 paragraphs. Also, respond thoughtfully to 2 of your fellow students' responses. Why is money so important in elections
|
Critically evaluates own strengths and weaknesses
: Critically evaluates own strengths and weaknesses with reference to the literature, drawing on a range of ideas to thoroughly investigate own practice and to highlight opportunities for contribution to society
|