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

how can I pass the size parameter in my input function by reference, this is the

ID: 3817212 • Letter: H

Question

how can I pass the size parameter in my input function by reference, this is the code

#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <ctime>

#include <math.h>

#include <fstream>

using namespace std;

//pass in the parameters

void inputData(double score[],int type[], int max[], int size){

//open the input file

ifstream intput("X:\Downloads\lab4input.txt");

if (intput)

{

cout << "quizz grades my guy " << endl;

}

//In the while condition, add the instream variable

while (intput >> score[size] >> type[size] >> max[size])

{

size++;

}

//clsoe the file

intput.close();

}

int main() {

//Array to store the scores

double score[50];

//Array to store the types

int type[50];

//Array to store the max points

int max[50];

//Size

int size = 0;

inputData(score, type, max, size);

for (int i = 0; i < size; i++) {

if (score[i] == 1)

{

cout << "score [" << i << "]:" << score[i] << endl;

}

}

for (int i = 0; i < size; i++) {

if (type[i] == 1)

{

cout << "type [" << i << "]:" << type[i] << endl;

}

}for (int i = 0; i < size; i++) {

if (max[i] == 1) {

cout << "max [" << i << "]:" << max[i] << endl;

}

cout << type[i];

cout << max[i];

cout << score[i];

}

system(" pause");

return 0;

}

Explanation / Answer

Do it in this way : &size , see the code I have tested and it works fine for me. You can test

#include <iostream>
#include <stdio.h>
using namespace std;
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <ctime>

#include <math.h>

#include <fstream>

using namespace std;

//pass in the parameters
void inputData(double score[],int type[], int max[], int &size){
//open the input file
ifstream intput("X:\Downloads\lab4input.txt");

if (intput)
{
cout << "quizz grades my guy " << endl;

}

//In the while condition, add the instream variable

while (intput >> score[size] >> type[size] >> max[size])

{

size++;

}

//clsoe the file
intput.close();
}
int main() {

//Array to store the scores

double score[50];

//Array to store the types

int type[50];

//Array to store the max points

int max[50];

//Size

int size = 0;

inputData(score, type, max, size);

for (int i = 0; i < size; i++) {

if (score[i] == 1)

{

cout << "score [" << i << "]:" << score[i] << endl;

}
}
//out<<size<<endl;

for (int i = 0; i < size; i++) {
if (type[i] == 1)
{
cout << "type [" << i << "]:" << type[i] << endl;

}

}for (int i = 0; i < size; i++) {

if (max[i] == 1) {

cout << "max [" << i << "]:" << max[i] << endl;

}

cout << type[i];

cout << max[i];

cout << score[i];

}
system(" pause");

return 0;

}

===

You can check by printing size at int main() to confirm if it works or not.

Thanks a lot, let me know if there is any concern.