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

154 - 6 279 215 404 391 - 166 199 - 302 - 469 244 0 - 20 405 110 118 359 305 77

ID: 3740220 • Letter: 1

Question

154

- 6

279

215

404

391

- 166

199

- 302

- 469

244

0

- 20

405

110

118

359

305

77

- 317

- 260

387

- 471

- 10

- 332

479

213

0

- 29

- 440

182

- 458

- 429

22

- 403

318

318

222

- 350

160

19

473

149

300

- 46

- 68

325

- 417

- 367

- 327

- 109

331

303

- 440

- 101

27

- 83

157

128

- 208

- 68

- 485

484

- 333

- 394

- 128

- 302

- 10

- 161

452

420

- 447

238

- 231

- 77

48

443

- 82

483

- 199

201

166

39

198

167

- 322

- 372

499

- 329

- 467

61

382

169

- 310

- 131

- 39

482

- 344

356

145

- 124

- 309

- 72

- 18

- 379

90

- 274

- 115

83

- 248

- 210

117

- 235

324

483

230

- 156

84

- 392

406

380

318

- 239

94

- 477

- 75

- 187

- 339

- 321

- 77

- 406

99

- 29

196

200

139

- 466

- 431

- 180

31

154

- 92

320

218

469

31

- 175

- 394

111

279

- 77

- 409

- 234

- 346

- 219

- 60

27

- 43

375

18

444

138

458

- 259

176

- 211

172

195

- 432

- 245

- 276

168

344

- 156

281

175

- 493

102

- 113

416

- 499

- 38

- 76

- 39

270

- 178

285

- 29

- 464

- 324

222

- 27

- 347

- 159

107

- 308

238

- 257

417

- 231

266

- 311

- 213

- 409

76

183

47

- 74

144

148

179

136

445

- 291

209

- 264

- 381

107

- 50

- 41

162

270

- 150

162

- 84

342

333

- 244

113

82

41

370

- 235

- 182

- 381

440

146

- 21

139

45

147

44

221

22

494

- 281

- 394

- 390

- 436

- 95

- 52

- 134

264

128

272

433

473

- 308

- 361

196

- 406

25

30

361

- 15

- 107

171

241

20

- 152

- 350

Goals: Practicing arrays and functions Create a program that will read values from a file called Lab8.dat (posted on Canvas) and store it into an array using a function other than main. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be returned to the function call. Your program should contain another function that accepts the array, the number of values in the array, and a whole number. This function should use a loop to count how many values in the array are evenly divisible by the whole number and return this count to the function call. The loop should not contain more than 3 arithmetic operatorsand+count as arithmetic operators, but does not) The main function should call the function to read the data from the file. Next, ask the user to enter a whole number between 2 and 20 (you may assume the user enters a correct value). This whole number is the value to divide each element in the array. Next, call the function to determine how many values in the file are evenly divisible by the entered whole number and output the returned count. The message should be something like 35 of the 182 values in the file were evenly divisible by 19. with the underlined values replaced by the your calculated values and the user's input. Do not use any concepts beyond Chapter 7 of your tex he introductory comments for the program your code should contain comments for each function other than main that states the purpose of the function, input to the function (b nput from the function call and interactive input), output from the function (both information sent back to the function call and interactive output), and processing performed in the function. Follow the Assignment Guidelines posted on Canvas. oth

Explanation / Answer

Code

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

int readFile(string,int[]);

void detectWhole(int[],int,int);

int main()

{

int num;

   cout<<"Enter the number -->";

   cin>>num;

   int numbers[300];

int n=readFile("Lab8.txt",numbers);

   cout<<"The number of integers in a file is-->"<<n<<endl;

   detectWhole(numbers,n,num);

   return 0;
}

int readFile(string filename, int number[])

{

   int num;

   int count=0;

   ifstream in(filename,ios::in);

   if(in.is_open())

   {

   while((in>>num)>0)

   {

       number[count]=num;

       count++;

   }

   in.close();

   }

   else

       cout<<"unable to open file"<<endl;

   cout << "Numbers: ";

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

       cout << number[i] << ' ';
   }

   return count;

}

void detectWhole(int number[],int n,int num)

{

   int count=0;

   for(int i=0;i<n;i++)

   {

       if(number[i]%num==0)

           count++;

      
   }

   cout<<count<<" of the "<<n<<" values in the file were evenly divisible by "<<num<<endl;

}

If any queries please get back to me

Thank You

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