Question

to solve the following problems, and then repeat using a For 111 NS, use a for-loop while-loop I. Create a vector containing values ofa measurement in inches spanning from 0 to 24 inches. Use these values to create a conversion table from inches to feet and display the result
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program using For loop:

#include <iostream>
#include <vector>
#include <iomanip> // std::setprecision
using namespace std;

int main()
{
   //Declaring variables
   double res;
  
   //Declaring vector
vector<int> vec;
  
//This loop will populates the inches values into vector
for(int i=0;i<=24;i++)
{
   vec.push_back(i);
   }
  
   //Setting the precision to 2 decimal places
   std::cout << std::setprecision(2) << std::fixed;
  
   //Displaying the inches and feet table
   cout<<"Inches\t\tFeet"<<endl;
   cout<<"--------------------"<<endl;
   for(int i=0;i<vec.size();i++)
   {
       res=i*0.0833333;
       cout<<i<<"\t\t"<<res<<endl;
   }

return 0;
}

___________________

Program Using While loop:

#include <iostream>
#include <vector>
#include <iomanip> // std::setprecision
using namespace std;

int main()
{
   //Declaring variables
   double res;
  
   //Declaring vector
vector<int> vec;

int i=0;

while(i<=24)
{
    vec.push_back(i);
    i++;
}

int len=vec.size();

    //Setting the precision to 2 decimal places
   std::cout << std::setprecision(2) << std::fixed;
    //Displaying the inches and feet table
   cout<<"Inches\t\tFeet"<<endl;
   cout<<"--------------------"<<endl;
   i=0;
while(i<=len)
{
            res=i*0.0833333;
       cout<<i<<"\t\t"<<res<<endl;
       i++;
}

return 0;
}

______________________

output:

CProgram Files (x86) Dev-Cpp MinGW64 binInchesToFeetinVector.exe Inches Feet 0.00 0.08 0.1? 0.25 0.33 0.42 0.50 0.58 0.6? 0.7

___________Thank You

Add a comment
Know the answer?
Add Answer to:
Use a for-loop to solve the following problems, and then repeat using a while-loop. Create 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 mat lab to do it Create a single script file named yourname_While.m to answer the...

    Using mat lab to do it Create a single script file named yourname_While.m to answer the following problems. The file must be in cell mode to distinguish each problem. Make sure your script is nicely commented for each problem. Consider the following matrix of values: x =[345, 23, 17, 34, 85, 334, 111, 1067] Use a for loop and if statement to determine how many values greater than 30? Use fprintf to display the result. Repeat Problem 1., but use...

  • 1. Create an PL/SQL anonymous block. Using a “while” loop, display on the console those rows where a quantity of shipmen...

    1. Create an PL/SQL anonymous block. Using a “while” loop, display on the console those rows where a quantity of shipments for a project are greater than the average quantity of shipments for that project. 2. Repeat using a FOR loop. // TABLE INFO : SHIPMENTS(SUPPLIERNO, PARTNO, PROJECTNO, QUANTITY, SHIPDATE, ARRIVEDATE)

  • Create function files that will use a “for” loop to perform the following tasks for a...

    Create function files that will use a “for” loop to perform the following tasks for a random input array “x”: (a) Count how many elements are greater than an arbitrary integer. Display these values as well as the count using “fprintf”. (b) Calculate the arithmetic mean of array “x” without using the built-in functions “sum”, “mean”, etc. and display the result using “fprintf”.

  • Having trouble with the do while/while loop and the switch statement. I got some of the...

    Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...

  • In Javascript: While loop: use a while loop to calculate and display the Kelvin temperature values...

    In Javascript: While loop: use a while loop to calculate and display the Kelvin temperature values for each Fahrenheit temperature value range from 0 to 100 in increment of 10. use the formula tk = (tf -32) x 5/9 + 273.15    The values should be displayed exactly as shown: -17, -12, -6, -1, 4, 10, 15, 21, 26, 32, 37

  • write a java program that does the following Part one Use a For loop to compute...

    write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...

  • Create a while loop that will execute the following code 12 times using a counter that...

    Create a while loop that will execute the following code 12 times using a counter that starts at 1 and is incremented by 1 each time through the loop. Within the while loop, create a switch statement that will print out the number of days in each of the months of the year. - Use fall through capabilities so that you only have one print statement for all of the months that contain 31 days. Do not worry about leap...

  • Using R, solve these problems: 1) 2) 3) Exercises • Create a vector grades=c(88,90,70,50) • Add...

    Using R, solve these problems: 1) 2) 3) Exercises • Create a vector grades=c(88,90,70,50) • Add names to the vector: Jon Snow, Tyrion, Arya, Cersei • Delete Cersei grade • Change Arya grade to 85 Exercises • Create the following vector [roquefort, ham, chicken liver, beef tongue, beef heart, mozzarella, watermelon] • Create a logical vector: True if you like the food, False otherwise. • Use the logical vector to select the food you like. • Create a new vector...

  • use MatLab to answer these questions 1. (10 points) Create an m-file called addup.m Use a...

    use MatLab to answer these questions 1. (10 points) Create an m-file called addup.m Use a for loop with k = 1 to 8 to sum the terms in this sequence: x(k) = 1/3 Before the loop set sumx = 0 Then add each term to sumx inside the loop. (You do not need to store the individual values of the sequence; it is sufficient to add each term to the sum.) After the loop, display sumx with either disp()...

  • please Dont solve problem 5 , solve problem 6 using vector loop Problem # 5. Referring to the linkage configuration...

    please Dont solve problem 5 , solve problem 6 using vector loop Problem # 5. Referring to the linkage configuration and terminology shown in the Figure below, draw the linkage to scale and graphically find all possible solutions for 0 and 04 for the values in a and b. Determine the Grashof condition. Link 1 Link 2 Link 3 Link 4 6 2 7 9 30 20 10 10 10 50 AY Open F 84 X Crossed Problem #6: Repeat...

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