Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROBLEM TresKom was hired by the previous government to account for expenses in

ID: 3832264 • Letter: P

Question

PROBLEM

TresKom was hired by the previous government to account for expenses in the Choliseo VIP lounge. The new government of the republic, made up of engineers with impeccable behavior wants to improve the code of TresCom engineers. However, the TresCom engineers were so inept that they did not create functions and put all the code in the main. We hope you do the work as it should have been done in the beginning!

1.  Move lines 11 to 14 to a function that will be called verificaMemory.

2.  Move lines 16 to 20 to a function that will be called readComilona (keywords: comilona = abundant food accompanied with expensive wines and incredible desserts. Corrupt = politician).

3.  Move lines 22 to 27 to a function that will be called PrintComilonayTotal.

4.  In the PrintComilonayTotal function, in addition to printing the comilonas, you must calculate and print also the total amount of money spent on the comilonas (the total).

CODE

//3Com.Enaudi.inc todos los torcidos corruptados
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
   float *gastos;
   int numOfgastos;
   cout << "Entre el numero total de fiestas: ";
   cin >> numOfgastos;
   gastos = new float[numOfgastos];
   if (gastos == NULL){
       cout << "Eror allocating memory, bye!!!";
       return -1;
   }
   cout << "Entre la factura de su comilona corrupta ";
   for (int i = 0; i < numOfgastos; i++){
       cout << "Leyendo Comilona " << i + 1;
       cout << " en posicion de memoria: " << gastos + i << " : ";
       cin >> *(gastos + i);
   }
   //Display gastos to verify they are inside the computer
   for (int i = 0; i < numOfgastos; i++) {
       cout << " Comilona numero " << i + 1;
       cout << " en direccion de memoria: " << gastos + i;
       cout << " con valor de: ";
       cout << *(gastos + i);
   }
   delete[] gastos;
   return 0;
}

Explanation / Answer

Please find the code below:

//3Com.Enaudi.inc todos los torcidos corruptados
#include <iostream>
#include <iomanip>
using namespace std;

bool verificaMemory(float*);
void readComilona(float*, int);
void PrintComilonayTotal(float*, int);

int main(){
float *gastos;
int numOfgastos;
cout << "Entre el numero total de fiestas: ";
cin >> numOfgastos;
gastos = new float[numOfgastos];

if (!verificaMemory(gastos))
       return -1;

cout << "Entre la factura de su comilona corrupta ";
readComilona(gastos,numOfgastos);

//Display gastos to verify they are inside the computer
PrintComilonayTotal(gastos,numOfgastos);

delete[] gastos;
return 0;
}

bool verificaMemory(float* gastos)
{
if (gastos == NULL){
cout << "Eror allocating memory, bye!!!";
return false;
}
   else
       return true;
}

void readComilona(float* gastos, int numOfgastos)
{
for (int i = 0; i < numOfgastos; i++){
cout << "Leyendo Comilona " << i + 1;
cout << " en posicion de memoria: " << gastos + i << " : ";
cin >> *(gastos + i);
}
}

void PrintComilonayTotal(float* gastos, int numOfgastos )
{
   float sumComilonas = 0.0f;
  
for (int i = 0; i < numOfgastos; i++) {
cout << " Comilona numero " << i + 1;
cout << " en direccion de memoria: " << gastos + i;
cout << " con valor de: ";
cout << *(gastos + i);
       sumComilonas += *(gastos + i);
}
  
   cout<< " Sum : " << sumComilonas <<endl;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote