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
#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.
If the solution is helpful do like
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(); 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
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...
//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...
(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...
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):...
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...
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 <=...
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...
Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 2, 1, 2} and matchValue is 2 , then numMatches should be 3. Your code will be tested with the following values: * matchValue: 2, userValues: {2, 2, 1, 2} (as in the example program above) * matchValue: 0, userValues: {0, 0, 0, 0} * matchValue: 50, userValues: {10, 20, 30, 40} (Notes) #include <iostream> #include <vector> using namespace...
02. Log N Vector Due Sunday by 11:59pm Points 149 O(log(N)) Vector std::vector is pretty cool but it has one big problem: every once in a while, push_back has to create a whole new array and copy a bunch of elements which is O(n)! Luckily, we can do better, in terms of Big-O. The goal of this homework is to write a class that behaves like a vector but without the O(n) push_back. Whenever we run out of space, we'll...