ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 04 May 2017 My Price 9.00

write C++ code to compare cout and printf

Need some help with the C++code on Part A been trying to solve it but has been getting errors.

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{

cout

stop =clock();

cout}

 

C++ code:

 

 

Screenshot of output:

 

 

 

Why is one faster than the other?

 

 

Week 4 Lab—Optimizing Program Performance
TCO 4—Given the importance of speculating runtime costs of software, obtain an understanding of
certain details of how processors operate that impact code performance.
Scenario
In this week’s lab, you will look at timing operations and how different operations can take a
different amount of time to complete. Rubric
Point distribution for this activity
Lab Activity
Document Points
possible Part A 20 Part B 20
Total Points Points
received 40 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 <iostream>
#include <time.h>
using namespace std;
int main()
{
double start, stop;
start=clock();
for (int i=0;i<100;i++)
{
cout<<" The number is "+i<<endl;
} stop =clock();
cout<<"It took "<<(double(stop-start)/CLOCKS_PER_SEC)<<" seconds for cout"<<endl;
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 1
2
3
4
5
6
7
8
9
10
Release mode: Bubble sort
time Quick sort
time Bubble sort time: _________________________
Quick sort time: __________________________ Example output

Attachments:

Answers

(11)
Status NEW Posted 04 May 2017 07:05 AM My Price 9.00

-----------

Attachments

file 1493883813-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)