SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

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

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 3 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 30 Nov 2017 My Price 10.00

programmer must write correct code that is clear and concise.

Would like some help with my homework. Will tip well if it can be finished in 7 hours with explanations with what you did.

Week 4 Homework—Optimizing Program Performance

 

A programmer must write correct code that is clear and concise. There are also circumstances in which a programmer must write fast and efficient code. Processing video frames in real time must be fast. We will talk about ways to optimize code.

Given the following code, perform these operations to optimize the code. See Chapter 5 in the book for more details on code optimization. Please use comments to document all optimizations you have made to the code.

1.      Using switch instead of if

2.      Eliminating length calls out of the loop test

3.      Put the most used variables first when initializing variables

4.      Use prefix operations rather than postfix operations

5.      Loop unrolling—increase the number of elements computed in each iteration of a loop (i.e. instead of processing arrays separately, if you have two arrays of the same length, process them in parallel)

6.      Any other improvements you want to make

 

#include<iostream>

#include<vector>

#include<string>

usingnamespace std;

 

#include<iostream>

#include<vector>

#include<string>

usingnamespace std;

 

int main()

{

       //This program stores the items purchased at the grocery store. The price vector stores the prices for each item purchased.

       //The product name vector stores the products purchased and the category vector stores which category the item falls under.

       //Frozen foods have a 10% discount, snacks has a 5% discount, and produce has a 15% discount.

       //The total amount of items purchased should be calculated with a 7% tax rate.

       double sum;

       doubletax,totalAmount;

 

       vector<double> price;

       vector<string>productName;

       vector<char> category;

      

       price.push_back(4.5);

       price.push_back(10);

       price.push_back(1.25);

       price.push_back(2.75);

       price.push_back(9.50);

       productName.push_back("ice cream"); //Frozen food

       productName.push_back("pizza");  //Frozen food

       productName.push_back("apples"); //Produce

       productName.push_back("cheesy poofs"); //Snacks

       productName.push_back("bananas"); //Produce

       category.push_back('F');

       category.push_back('F');

       category.push_back('P');

       category.push_back('S');

       category.push_back('P');

 

       if (category[0]=='F')

       {

              price[0]=price[0]*.9;

       }

       elseif (category[0]=='S')

       {

              price[0]=price[0]*.95;

       }

       else

       {

              price[0]=price[0]*.85;

       }

       if (category[1]=='F')

       {

              price[1]=price[1]*.9;

       }

       elseif (category[1]=='S')

       {

              price[1]=price[1]*.95;

       }

       else

       {

              price[1]=price[1]*.85;

       }

              if (category[2]=='F')

       {

              price[2]=price[2]*.9;

       }

       elseif (category[2]=='S')

       {

              price[2]=price[2]*.95;

       }

       else

       {

              price[2]=price[2]*.85;

       }

              if (category[3]=='F')

       {

              price[3]=price[3]*.9;

       }

       elseif (category[3]=='S')

       {

              price[3]=price[3]*.95;

       }

       else

       {

              price[3]=price[3]*.85;

       }

              if (category[4]=='F')

       {

              price[4]=price[4]*.9;

       }

       elseif (category[4]=='S')

       {

              price[4]=price[4]*.95;

       }

       else

       {

              price[4]=price[4]*.85;

       }

 

       sum=price[0]+price[1]+price[2]+price[3]+price[4];

      

       for(inti=0;i<price.size();i++)

       {

              cout<<"The price for item "<<(i+1)<<" is "<<price[i]<<endl;

              tax=sum*.07;

              totalAmount = sum+tax;

       }

              for(inti=0;i<productName.size();i++)

       {

              cout<<"The product name for item "<<(i+1)<<" is "<<productName[i]<<endl;

       }

              cout<<"The total price is: "<<totalAmount<<endl;

              cin.ignore();

 

       return 0;

}

Attachments:

Answers

(5)
Status NEW Posted 30 Nov 2017 12:11 PM My Price 10.00

-----------  ----------- 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

Not Rated(0)