1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pishuonlain [190]
3 years ago
13

THE bestValue PROBLEM Using the Camera structure defined in file p1.cpp, write the function named bestValue(). The function take

s one input parameter: a vector of Camera. The vector is sorted by manufacturer, so all cameras of a particular manufacturer are together in the vector. The function returns a vector of string, with the manufacturer, model number and price concatenated together exactly in this format.
Computers and Technology
1 answer:
eduard3 years ago
3 0

Answer:

#include <iostream>

#include <vector>

#include <string>

#include <cmath>

#include <iomanip>

#include <sstream>

using namespace std;

// Given struct

struct Camera {

// Declaring variables

string manufacturer;

string model;

int releaseYear;

int resolution;

int weight;

double price;

};

vector<string> bestValue(const vector<Camera>& cameraNew) {

vector<string> display;

double winnerOne = 0;

double winnerTwo = 0;

double realWinnerOne = 0;

double realWinnerTwo = 0;

string displayOne;

string displayTwo;

string ans;

int find = 0;

// Calculating best value using given formula

for (unsigned i = 1; i < cameraNew.size(); i++) {

winnerOne = cameraNew[i].price / static_cast<double>(cameraNew[i].resolution);

winnerTwo = cameraNew[i-1].price / static_cast<double>(cameraNew[i - 1].resolution);

if (cameraNew[i].manufacturer == cameraNew[i - 1].manufacturer) {

if (winnerOne > winnerTwo && winnerOne > realWinnerOne) {

find = 1;

}

else if (winnerOne < winnerTwo && winnerTwo > realWinnerTwo) {

find = 2;

}

if (find == 1) {

realWinnerOne = cameraNew[i].price/ static_cast<double>(cameraNew[i].resolution) ;

ostringstream displayStream1;

displayStream1 << fixed << setprecision(2) << cameraNew[i].price;

displayOne = cameraNew[i].manufacturer + ":" + cameraNew[i].model + ":$" + displayStream1.str();

find = 0;

}

else if (find == 2) {

realWinnerTwo = cameraNew[i - 1].price / static_cast<double>(cameraNew[i - 1].resolution);

ostringstream displayStream2;

displayStream2 << fixed << setprecision(2) << cameraNew[i - 1].price;

displayTwo = cameraNew[i-1].manufacturer + ":" + cameraNew[i-1].model + ":$" + displayStream2.str();

find = 0;

}

}

else {

if (realWinnerOne >= realWinnerTwo) {

display.push_back(displayOne);

realWinnerOne = 0;

realWinnerTwo = 0;

}

else if (realWinnerOne < realWinnerTwo) {

display.push_back(displayTwo);

realWinnerOne = 0;

realWinnerTwo = 0;

}

}

}

if (realWinnerOne > realWinnerTwo) {

display.push_back(displayOne);

}

else if (realWinnerOne < realWinnerTwo) {

display.push_back(displayTwo);

}

else if (realWinnerOne == realWinnerTwo) {

display.push_back(displayTwo);

}

return display;

}

template <typename T>

ostream& operator<<(ostream& out, const vector<T>& display) {

if (display.size() > 0) {

out << "0. " << display[0];

out << endl;

//displaying output in the given format

for (size_t i = 1; i < display.size(); i++) {

out << i << ". " << display[i];

out << endl;

}

}

else

{

out << "Size of the vector is 0 or less than 0." << endl;

}

return out;

}

void camBestValue() {

const vector<Camera> vCameras = {

{ "Agfa", "ePhoto 1280", 1996, 1024, 400, 180 },

{ "Agfa", "ePhoto CL45", 2000, 1600, 275, 180 },

{ "Canon", "PowerShot 350", 1996, 640, 315, 150 },

{ "Canon", "PowerShot 600", 1994, 832, 445, 139 },

{ "Canon", "PowerShot A10", 2001, 1280, 355, 139 },

{ "Casio", "Exilim EX-P505", 2005, 2560, 250, 260 },

{ "Casio", "Exilim EX-P600", 2006, 2816, 275, 260 },

{ "Casio", "Exilim EX-P700", 2006, 3072, 275, 260 },

{ "Epson", "PhotoPC 800", 1997, 1600, 285, 220 },

{ "Epson", "PhotoPC L-500V", 2004, 2560, 205, 150 },

{ "Fujifilm", "FinePix 40i", 2000, 2400, 185, 180 },

{ "Fujifilm", "FinePix 50i", 2001, 2400, 205, 180 },

{ "Fujifilm", "DS-260HD", 1997, 1280, 845, 190 },

{ "Fujifilm", "DS-300", 1995, 1280, 845, 200 },

{ "HP", "Photosmart 320", 2002, 1632, 230, 190 },

{ "HP", "Photosmart 435", 2003, 2048, 180, 190 },

{ "HP", "Photosmart 620", 2002, 1632, 260, 190 },

};

vector<string> display;

display = bestValue(vCameras);

cout << display << endl;

}

int main() {

camBestValue();

}

Explanation:

The program takes one input parameter: a vector of Camera. The vector is sorted by manufacturer, so all cameras of a particular manufacturer are together in the vector.

The function returns a vector of string, with the manufacturer, model number and price concatenated together.

It produces the best value.

You might be interested in
Which statement best explains taxation without representation was a major issue for colonists?
Sauron [17]
Taxation without representation was a major issue for the colonists, because they were being unfairly taxed by the British without having a representative in the British Parliament to represent them ans state that they were against this. It was also one of the driving forces of the American Revolution, as it was just one of the grievances the colonists were experiencing from the British. 
4 0
3 years ago
Here is the header for a function named computeValue:
zhuklara [117]

Answer:

B) computeValue(10);

Explanation:

Given

Header: void computeValue(int value)

Required

Determine the valid call

To call a function from another function or from the main, the following syntax has to be used.

<em>function-name(parameter-1, parameter-2, parameter-3,.....,parameter-n);</em>

<em />

In the function header given:, the following can be observed:

  • The function name is computeValue
  • It has only one parameter and it is of type integer

So, to call the function; we make use of computeValue(10);

Where 10 represents the value of the parameter (i.e. argument)

7 0
2 years ago
When Hallmark designs its website so that a teenage girl can send a theme card to her boyfriend's cell phone, what is the primar
padilas [110]

Answer:

Hallmark is using the Age segmenting dimension.

Explanation:

Most businesses and organizations tend to understand their customers, that is, their behaviors on purchases.

There are 7 important ways businesses segment their customers. They are:

  1. Income
  2. Age
  3. Gender
  4. Acquisition Path
  5. First purchase
  6. Geography
  7. Device type

In our scenario, Hallmark is using the Age segmenting dimension because they can identify that its a teenage girl that is sending theme card to her boyfriend's cell phone.

7 0
2 years ago
In which of the following situations would you want to use a word processing template?
creativ13 [48]
<h2>Answer:</h2>

<u>The correct answer is A. </u><u>You need to write a letter to a company you’d like to work with, and have specific questions to ask.</u>

<h2>Explanation:</h2>

Applying for a job is a very formal type of document which contains all the required and necessary information about a person who wants to apply. So a letter is typed in Microsoft word format to keep the document aligned and beautiful. Word template can make it professional which otherwise becomes hard to apply for a job in the absence of quality editing.

5 0
3 years ago
Read 2 more answers
The natural functions of Earth seem all _____ in one way or another.
Sonja [21]
Would it be Similar ?
4 0
3 years ago
Other questions:
  • Why don't we get together to watch the Academy Awards?
    15·2 answers
  • For some brand-name computers, the hard drive contains a partition that can be used to reinstall windows. what is the name for t
    6·1 answer
  • A bus topology network is most often deployed as a peer-to-peer network. <br> a. True <br> b. False
    7·1 answer
  • A senior center would like to add a new computer to their library so that members can check their email and read book reviews
    11·2 answers
  • Which social media post indicates your home may be unattended?
    10·1 answer
  • List of steps to apply bold and italic formatting to a word​
    9·2 answers
  • To generate a report with exact results based on specific criteria it is best to base the report on a(n) ____________________ cr
    6·1 answer
  • Benching system are prohibited in
    5·1 answer
  • Write a program that asks a user to enter a date in month day year format (for example 10 12 2016) and displays the day of the w
    5·1 answer
  • Imagine that a team of scientists test a certain hypothesis, and the experimental results show that it is false.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!