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
Assume that ip has been declared to be a pointer to int and that enrollment has been declared to be an array of 20 elements . As
Vitek1552 [10]

Answer:

ip = enrollment + section;

Explanation:

The variable ip has been declared to be a pointer to int.

int * ip;

The variable enrollment has been declared as an array of 20 elements .

int enrollment[20];

The variable section has been declared as an int.

int section;

In order to make ip point to the element in the array indexed by section, we can use the following statement :

ip = enrollment + section;

This will make ip point to enrollment[section].

5 0
3 years ago
What can help establish the focus and organization it relies on? A) Plan B) programming C) organizing D) arranging
serg [7]

Organizational communication helps us to

1) accomplish tasks relating to specific roles and responsibilities of sales, services, and production

2) acclimate to changes through individual and organizational creativity and adaptation

3) complete tasks through the maintenance of policy, procedures, or regulations that support daily and continuous operations

4) develop relationships where “human messages are directed at people within the organization-their attitudes, morale, satisfaction, and fulfillment”

5) coordinate, plan, and control the operations of the organization through management.

So the answer is C.

hope it helps!

7 0
3 years ago
Read 2 more answers
Components that enhance the computing experience, such as computer keyboards, speakers, and webcams, are known as
never [62]

Answer:

- Peripheral devices

Explanation:

Peripheral devices are defined as computer devices which are not the element of the essential/basic computer function. These devices can be internal as well as external and are primarily connected to the computer for entering or getting information from the computer. For example, the keyboards or mouse functions to enter data into the computer for processing and receiving information while the output devices like speakers, projectors, printers, etc. are used to get the information out of the computer.

3 0
3 years ago
1
g100num [7]
Have a look at the man page for printf:

man 3 printf
4 0
3 years ago
Read 2 more answers
When building systems, the only two entities that constitute software engineering are people and process.
VLD [36.1K]

Answer: False

Explanation: Software engineering is the designing, analyzing, creating the software application as per the requirement of the user. The programming languages is the base for the designing of the application the software engineering field.

At the time of building system ,there is the requirement of many resources for the development.There is the requirement of the software skills, programming knowledge, resources and tools for the working and designing.Thus, there are different resources, people,skills processes, problem solving skill etc required for the building of the system.

7 0
3 years ago
Other questions:
  • Reputable firms often ask recent graduates to pay an up-front fee for a job.
    12·2 answers
  • A potential threat to administrators’ ability to manage the correctional system is
    12·1 answer
  • ​if a primary key combines two or more fields, then it is called a _____.
    14·1 answer
  • Which of the following is an accurate definition of a computer system? A computer system consists of the operating system that t
    6·1 answer
  • Charlie makes pizza at a restaurant. The customers always compliment how great the pizza tastes. But Charlie takes a long time t
    7·2 answers
  • Is Brainly cheating??
    10·2 answers
  • Being a part of an organization or giving back to the community is which rewards of work factor?
    6·1 answer
  • 5 differences between a regular mouse and a gaming mouse​
    14·1 answer
  • 2. What are some other reasons why you might need to know the operating system version on your computer or mobile device
    14·1 answer
  • What is the basic body structure of html.
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!