Questions 1. What is the size of the dynamic array in the code? a. gastos new fl
ID: 3832764 • Letter: Q
Question
Questions
1. What is the size of the dynamic array in the code?
a.
gastos new float[num OfGastos];
b.
gastos = new float[num OfGastos];
c.
gastos = new float[];
d.
numOfGastos
2. In the code, which means when you ask if (gastos == NULL)
a. NULL is being assigned to the pointer.
b. It verifies if the pointer is punctual.
c. It verifies if the pointer is not punctual.
d. It is checking if there is enough memory to reserve / allocate memory.
3. How do you write the prototype of the readHartera function?
a. Void readHartera (int expenses, int numOfgastos);
b. Void readHartera (float * expenses, int numOfgastos);
c. Void readHartera ();
d. Void readHartera (float expenses, int numOfgastos);
4. How do you write the amount of a hartera?
a. Cout << * (+ i);
b. Cout << * (expenditure + i);
c. Cout << i;
d. Cout << (expenditure + i);
5. what happens if the instruction delete [] gastos is not written ?;
a. Dynamic array memory is not freed.
b. Nothing happens;
c. The computer fills with viruses and explodes.
d. The computer memory is erased.
CODE
//3Com.Enaudi.inc todos los torcidos corruptados
#include "stdafx.h"
//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;
system("pause");
}
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;
system("pause");
}
a.
gastos new float[num OfGastos];
b.
gastos = new float[num OfGastos];
c.
gastos = new float[];
d.
numOfGastos
Explanation / Answer
1. What is the size of the dynamic array in the code ?
d.
numOfGastos
//Because that is the size of array
2. In the code, which means when you ask if (gastos == NULL)
c. It verifies if the pointer is not punctual.
//It checks if pointer is not pointing to any location
3. How do you write the prototype of the readHartera function?
b. Void readHartera (float * expenses, int numOfgastos);
//this is how other read functions are declared
4. How do you write the amount of a hartera?
b. Cout << * (expenditure + i);
//accessing an array using pointers is done in above way
5. what happens if the instruction delete [] gastos is not written ?;
a. Dynamic array memory is not freed.
//We created a memory , its our responsiblity to free it , if we dont do still nothing will happen but our memory is not freed
Thanks, Answers are mostly sure short, Need not worry about it..Thanks
d.
numOfGastos
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.