Question

Properly format the following code such that the scope of each code block is properly indented....

Properly format the following code such that the scope of each code block is properly indented. #include #include using namespace std; void method2(int& mult){ mult *= 2; } void method1(int& count){ count += 2; } int main(){ chrono::time_point start; chrono::time_point end; int mult = 1, count = 0; int nums[] = {1,2,3,4,5,6,7}; int choice; cout << "Enter your choice (1 or 2): "; cin >> choice; const int maxReps = 31; switch(choice){ //method 1 case 1: start = chrono::system_clock::now(); for(int i = 0; i < maxReps; i++) method1(count); end = chrono::system_clock::now(); break; //method 2 case 2: start = chrono::system_clock::now(); for(int i = 0; i < maxReps; i++) method2(mult); end = chrono::system_clock::now(); break; //etc on cases default: break; } chrono::duration elapsed = end-start; cout << "Total time in seconds: " << elapsed.count() << endl; cout << "count = " << count << " mult = " << mult << endl; }

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <chrono>

using namespace std;

void method2(int& mult)
{
   mult *= 2;
}

void method1(int& count)
{
   count += 2;
}

int main()
{
  using namespace std::chrono;

   chrono::time_point start;
   chrono::time_point end;
   int mult = 1, count = 0;
   int nums[] = {1,2,3,4,5,6,7};
   int choice;
   
   cout << "Enter your choice (1 or 2): ";
   cin >> choice;
   const int maxReps = 31;
   
   switch(choice)
   {
      //method 1 
      case 1: start = chrono::system_clock::now(); 
            for (int i = 0; i < maxReps; i++)
               method1(count);
            end = chrono::system_clock::now(); 
            break; 
      
      //method 2
      case 2: start = chrono::system_clock::now();
            for(int i = 0; i < maxReps; i++)
               method2(mult);
            end = chrono::system_clock::now();
            break;
      
      //etc on cases
      default: break;
   }
   
   chrono::duration elapsed = end-start;
   cout << "Total time in seconds: " << elapsed.count() << endl;
   cout << "count = " << count << " mult = " << mult << endl;

   return 0;
}

Note: The complete code is included with proper indentation.

Add a comment
Know the answer?
Add Answer to:
Properly format the following code such that the scope of each code block is properly indented....
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
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