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
In PKI, the CA periodically distributes a(n) _________ to all users that identifies all revoked certificates.
Trava [24]

Answer:

" CRL (certificate revocation list)" is the appropriate answer.

Explanation:

  • A collection of such subscriber bases containing accreditation or certification status combined with the validation, revocation, or outdated certification within each final customer is known as CRL.
  • Only certain subscribing workstations with a certain underlying cause authentication system should have been duplicated.
4 0
3 years ago
In many DBMSs where no strict separation of levels is maintained, this one language is used by the DBA and database designers to
marissa [1.9K]

Answer: False

Explanation:

This means that the mappings between the two schemas may be specified in either one of these languages.In most relational DBMSs today, there is no specific language that performs the role of SDL. Instead, the internal schema is specified by a combination of functions, parameters, and specifications related to storage. These permit the DBA staff to control indexing choices and mapping of data to storage

5 0
3 years ago
Whats a good way to remember to log out
Gemiola [76]
You just need to set a reminder on your phone and try and remember

3 0
3 years ago
Trish has bought a new computer, which she plans to start working on after a week. Since Trish has not used computers in the pas
Nikolay [14]

Answer:

The answer is C

Explanation

She should sign an annual maintenance contract (AMC) with her vendor

3 0
3 years ago
Read 2 more answers
5.8.1 Ghosts Python Codehs
eduard

To use Ghost's Python Codehs, we need to install Pygame, for it to work.

<h3>How to use pygame?</h3>

Pygame has several ways to install. Let's do the installation here from the PyCharm environment itself. In the project interpreter, the new virtual environment is already configured, you click on the plus sign, type Pygame, check if it is this one. There's a lot of Pygame, but it's this one alone, with nothing, version 9.6. Click on it and on the installation package button.

If all goes well, Pygame will be successfully installed, and you will be able to use it in your project.

Learn more about code brainly.com/question/497311

8 0
2 years ago
Other questions:
  • What does snap do need the answer now
    10·2 answers
  • how can you create fades with the smart tool? How can you specify the types of fade curves that are used with the smart tool?
    13·1 answer
  • I need some help pleas hurry
    5·1 answer
  • When a security professional is presented with a contract drawn up by a company's legal department, which allows them to "hack"
    13·1 answer
  • In ____, two or more disk drives become one large volume, so the computer views the disks as a single disk.
    13·1 answer
  • When you open a browser window, it open in a _____. <br> a. fieldb. folderc. menud. window?
    7·1 answer
  • Given a number count the total number of digits in a number
    12·1 answer
  • what is musical technology specifically, the origins of its genesis &amp; its importance to the baroque era
    6·1 answer
  • Guys how can i video my self from my laptop <br> my laptop is (lenovo)
    8·2 answers
  • Is permanent software programmed into read-only memory.<br> Firmware<br> JavaScript<br> PHP<br> o
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!