Question
Part A: We will look at timing operations in C++. To see the difference in operations, write C++ code to compare cout and printf, and
Part A:
We will look at timing operations in C++. To see the difference in operations, write C++ code to compare cout and printf, and display the time difference for 100 cout operations and 100 printf operations. This code can be written in Visual Studio. Below is how you would time the 100 cout operations in Visual Studio. Add another for loop, and display time for both cout and printf then comment about why you think there is a difference.
#include
#include
using namespace std;
int main()
{
double start, stop;
start=clock();
for (int i=0;i<100;i++)
{
cout<<" The number is "+i< } stop =clock(); cout<<"It took "<<(double(stop-start)/CLOCKS_PER_SEC)<<" seconds for cout"< cin.ignore(); } C++ code: Screenshot of output: Why is one faster than the other? Part B: Next, we will take timing a step further. There are a few different sorting algorithms, and these algorithms have varying time complexity. For this part of the lab, we will implement bubble sort and quick sort. Research bubble sort and quick sort algorithms, and implement them in C++. Fill a large array (maybe 15,000 elements) of random numbers. Then time the difference between bubble sort and quick sort 10 times, and fill out the table. Next, run the program in release mode. Did you notice a difference in time? Copy your C++ code here. Debug mode: Iteration Bubble sort time Quick sort time 1 2 3 4 5 6 7 8 9 10 Release mode: Bubble sort time: _________________________ Quick sort time: __________________________
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started