Question

void makeSales (std::vector<Salesman*> &s) { // Assign sales in dollar amounts to each salesman s[0]->addSale(); s[0]->addSale();...

void makeSales

(std::vector<Salesman*> &s)

{

// Assign sales in dollar amounts to each salesman

s[0]->addSale();

s[0]->addSale();

s[1]->addSale();

s[1]->addSale();

s[2]->addSale();

s[2]->addSale();

s[2]->addSale();

s[2]->addSale();

s[3]->addSale();

s[3]->addSale();

return;

}

Please make code above in C++

addSale: accepts a float and appends that value to the vector of sales; returns void

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>

using namespace std;

vector<float>v[1005];//declaring the vector as //global

void addsale(float p,int i)//here p is the float //value that is to be pushed and i is the index of //the vector

{

v[i].push_back(p);

}

int main()

{

//taking values as input to push to vector

addsale(1000.0,0);

addsale(1453.0,0);

addsale(2000.0,1);

addsale(2453.0,1);

addsale(35.0,2);

addsale(145.99,2);

addsale(18853.25,2);

addsale(176.25,2);

addsale(1000.0,3);

addsale(1453.0,3);

//finally printing the values to see the values

for(int i=0;i<4;i++)

{

cout<<"values at index"<<i<<":";

for(auto it=v[i].begin();it!=v[i].end();++it)

{

cout<<*it<<" ";

}

cout<<"\n";

}

}

output:

values at index0:1000 1453

values at index1:2000 2453

values at index2:35 145.99 18853.2 176.25

values at index3:1000 1453

You can change the values and size of the vector and above is the implementation of addsale function as well as I have also printed the values.

Add a comment
Know the answer?
Add Answer to:
void makeSales (std::vector<Salesman*> &s) { // Assign sales in dollar amounts to each salesman s[0]->addSale(); s[0]->addSale();...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • void makeSales (std::vector<Salesman*> &s) { // Assign sales in dollar amounts to each salesman s[0]->addSale(1000.0); s[0]->addSale(1453.0);...

    void makeSales (std::vector<Salesman*> &s) { // Assign sales in dollar amounts to each salesman s[0]->addSale(1000.0); s[0]->addSale(1453.0); s[1]->addSale(2000.0); s[1]->addSale(2453.0); s[2]->addSale(35.0); s[2]->addSale(145.99); s[2]->addSale(18853.25); s[2]->addSale(176.25); s[3]->addSale(1000.0); s[3]->addSale(1453.0); return; } Please make code above. addSale: accepts a float and appends that value to the vector of sales; returns void

  • Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and...

    Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...

  • (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0)...

    (a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...

  • //trendtracker.h #ifndef TRENDTRACKER_H #define TRENDTRACKER_H #include <vector> #include <string> using namespace std; class Trendtracker { public:...

    //trendtracker.h #ifndef TRENDTRACKER_H #define TRENDTRACKER_H #include <vector> #include <string> using namespace std; class Trendtracker { public:    Trendtracker();    void insert(string ht);    int size();       void tweeted(string ht);    int popularity(string name);    string top_trend();    void top_three_trends(vector<string> &T);    void top_k_trends(vector<string> &T, int k); private:    class Entry    {    public:        string hashtag;        int pop;    }; vector<Entry> E; }; #endif //trendtracker.cpp #include"trendtracker.h" using namespace std; // Creates a new Trendtracker tracking...

  • Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std;...

    Fix the following program (C++). #include <iostream> #include <cmath> #include <vector> #include <limits> using namespace std; /* * Calculate the square of a number */ float square (float x) { return x*x; } /* * Calculate the average from a list of floating point numbers */ float average(vector<float>& values) { float sum = 0.0f; float average; for (float x : values) sum += x; average = sum / values.size(); return average; } /** Calculate the standard deviation from a vector...

  • Explain the results 푤include using nanespace std: int nain (O rloat arr[s- (12.5,.11.0, 13.8, 1...

    Explain the results 푤include <iostream> using nanespace std: int nain (O rloat arr[s- (12.5,.11.0, 13.8, 1000.5, 1.5): float ptri-arEIo1: float *ptr2"ptri +3: cout<< +ptr2xcend *ptr2-* (ptr2)+1: //Line 16 cout<< ptr2<<endl: return 0; Bxplaing the results. 5 What Happens if the Line 16 is replaced by *ptr2- (ptr2+1): 6. tincludekiostream> using namespace std: void fun (int arr(I) int for air size = arestizer) isizeor (arr10]); for (i=0;遠くarr size: i++) int main(0 int int array 114](10, 20 30, 401 fun (array 1):...

  • Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n)...

    Example program #include <string> #include <iostream> #include <cmath> #include <vector> using namespace std; vector<int> factor(int n) {     vector <int> v1;     // Print the number of 2s that divide n     while (n%2 == 0)     {         printf("%d ", 2);         n = n/2;         v1.push_back(2);     }     // n must be odd at this point. So we can skip     // one element (Note i = i +2)     for (int i = 3; i <=...

  • I need help with the code below. It is a C program, NOT C++. It can...

    I need help with the code below. It is a C program, NOT C++. It can only include '.h' libraries. I believe the program is in C++, but it must be a C program. Please help. // // main.c // float_stack_class_c_9_29 // // /* Given the API for a (fixed size), floating point stack class, write the code to create a stack class (in C). */ #include #include #include #include header file to read and print the output on console...

  • Coding Language: C++ Function Header: vector<vector<int>> printFromButtom(TreeNode* root) {} Definition for a binary tree node: struct...

    Coding Language: C++ Function Header: vector<vector<int>> printFromButtom(TreeNode* root) {} Definition for a binary tree node: struct TreeNode { int val; TreeNode *left; TreeNode *right; }; The Problem Complete the printFromButtom function that accepts a BST TreeNode and returns the nodes' value from left to right, level by level from leaf to root. This function will return vector<vector int which similar to a 2-D array. Function std: reverse (myvector.begin myVector en might be helpful. Definition for a binary tree node: struct...

  • Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for...

    Hi, I have C++ programming problem here: Problem: Please modify your string type vector in for push_back() function as below: void push_back(string str) { // increase vector size by one // initialize the new element with str } In addition, the standard library vector doesn't provide push_front(). Implement push_front() for your vector. Test your code with the main function below. int main() {    vector v1(3);    cout<<"v1: ";    v1.print(); // this should display -, -, -    for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT