I need my constructor to start every element of my array in 0.0
, but with my code it tells me that:
Error C2512 'Vendedor': no appropriate default constructor available".
Annex the code:
#pragma once
#include <iostream>
#include <iomanip>
using namespace std;
class Vendedor
{
public:
Vendedor(float Ventas[12]);
void asignaventas(float);
void imprimeventas();
private:
float Ventas[12];
float VentasTotal;
float CalVtasTotal(float);
float Ventastotal =0; }
#include "Vendedor.h"
#include <iostream>
using namespace std;
Vendedor::Vendedor(float Ventas[12]) {
for (int i = 0; i < 12; i++) {
this->Ventas[i] = 0.0f;
}
}
void Vendedor::asignaventas(float Ventas) {
float x = 0;
cout << "Introdusca la cantidad de ventas realizadas en los 12 meses: "<<endl;
for (int i = 0; i < 12; i++) {
cin >> x;
this->Ventas[i] = x;
}
}
void Vendedor::imprimeventas() {
cout << " Las ventas ascienden a: " << CalVtasTotal(Ventas[12]) << endl;;
}
float Vendedor::CalVtasTotal(float Ventas) {
float total = 0;
for (int i = 0; i < 12; i++) {
total = total + this->Ventas[i];
}
this->VentasTotal = total;
return VentasTotal;
}
#include <iostream>
#include "Vendedor.h"
using namespace std;
int main(int argc, char *argv[]) {
Vendedor ob; //aquí marca el error
ob.asignaventas(12);
ob.imprimeventas();
return 0;
}