Forum » Programiranje » c++ vector napaka!!
c++ vector napaka!!
kretze ::
#include <iostream> #include <stdlib.h> #include <string> #include<vector> #include<iomanip> using namespace std; void initVectors(vector <int>&id, vector<int>&units, vector<double>&prices) { for (int i = 914; i <= 922; i++) id.push_back(i); units.push_back(842); units.push_back(416); units.push_back(127); units.push_back(514); units.push_back(514); units.push_back(437); units.push_back(269); units.push_back(97); units.push_back(492); units.push_back(212); prices.push_back(12.95); prices.push_back(14.95); prices.push_back(18.95); prices.push_back(16.95); prices.push_back(21.95); prices.push_back(31.95); prices.push_back(14.95); prices.push_back(14.95); prices.push_back(16.95); } void calsSales(vector<int>units, vector<double>prices, vector<double>&sales) { for (int i = 0; i< units.size(); i++) sales.push_back(units[i]*prices[i]); } void dualSort(vector<int>&id, vector<double>&sales) { int maxIndex, temp, size; double maxValue; size = id.size(); for (int i = 0; i < (size - 1); i++) { maxIndex = i; maxValue = sales[i]; temp = id[i]; for (int j = i + 1; j < size; j++) { if (sales[j] > maxValue) { maxValue = sales[j]; temp = id[j]; maxIndex = j; } } sales[maxIndex] = sales[i]; id[maxIndex] = id[i]; sales[i] = maxValue; id[i] = temp; } } void showOrder(vector<double>sales, vector<int>id) { cout << "Product namber\tSales\n"; cout << "---------------------------------------\n;"; for (int i = 0; i < id.size(); i++) { cout << id[i] << " \t\t$"; cout << setw(8) << sales[i] << endl; } cout << endl; } void showTotals(vector<double>sales, vector<int>units) { int totalunits = 0; double totalSales = 0.0; for (int i = 0; i < units.size(); i++) { totalunits += units[i]; totalSales += sales[i]; } cout << "total units sold " << totalunits << endl; cout << "total sales " << totalSales << endl; } int main() { vector<int>id; vector<int>units; vector<double>prices; vector<double>sales; initVectors(id, units, prices); calsSales(units, prices, sales); dualSort(id, sales); cout << fixed << showpoint << setprecision(2); showOrder(sales, id); showTotals(sales, units); system("pause");// return 0; }
BivšiUser2 ::
Najprej pokaži napredek pri prejšnji nalogi (Nogomet).
SloTech - če nisi z nami, si persona non grata.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | c++ rabim pomoč konstuktorjiOddelek: Programiranje | 1098 (793) | Snowflake2 |
» | [C#] Min in Max vrednosti spremenljivkOddelek: Programiranje | 779 (506) | MrBrdo |
» | En easy program v cOddelek: Programiranje | 784 (491) | XsenO |
» | Linux Synaptics touchpad driverjiOddelek: Operacijski sistemi | 1099 (976) | preem |
» | [C++] Functor za izračun osnovne statistike podatk. strukture (vector,list...)Oddelek: Programiranje | 1480 (1393) | Vesoljc |