2.1 Task 1: Arrays and Pointers For this task, you are required to provide files called arrP.cpp as well as a makefile to compile and run it. In your file, arrP.cpp, should have a skeleton of a main program as per normal which you will then fill it in as per the following. The objective of this task is to demonstrate the use of pointers for creating dynamic arrays. Specifically, through the use of pointers, it is possible to create arrays of a dy- namic size. That is, to create an array of a specific size that can be altered as needed. The type should be integer. Your program will need to read from a file called values.txt. This file has the following format: 4;1,2,3,4 3;6,7,9 The above refers to a line with two components: size and the values of an array. The first number before the semi-colon, refers to the size of the array. What follows afterwards are the values that should go in that array. The number of lines you will have to read is not specified. You will read from this file, line by line, each of the lines, and then store the values in the array. Then the following operation should be done: • If the largest element in the array is odd, square every value in the array and display the array, as a single comma delimited line with a new line at the end. • If the largest element in the array is even, multiply every value by the largest value in the array and display the array, as a single comma delimited line with a new line at the end. An example of the output given the above file would be: 4,8,12,16 36,49,81

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
### Task 1: Arrays and Pointers

For this task, you are required to provide files called `arrP.cpp` as well as a makefile to compile and run it. In your file, `arrP.cpp`, you should have a skeleton of a main program as per normal which you will then fill in as per the following.

The objective of this task is to demonstrate the use of pointers for creating dynamic arrays. Specifically, through the use of pointers, it is possible to create arrays of a dynamic size. That is, to create an array of a specific size that can be altered as needed. The type should be integer.

Your program will need to read from a file called `values.txt`. This file has the following format:

```
4;1,2,3,4
3;6,7,9
```

The above refers to a line with two components: size and the values of an array. The first number before the semi-colon, refers to the size of the array. What follows afterwards are the values that should go in that array. The number of lines you will have to read is not specified.

You will read from this file, line by line, each of the lines, and then store the values in the array. Then the following operation should be done:

- **If the largest element in the array is odd**, square every value in the array and display the array, as a single comma delimited line with a new line at the end.

- **If the largest element in the array is even**, multiply every value by the largest value in the array and display the array, as a single comma delimited line with a new line at the end.

An example of the output given the above file would be:

```
4,8,12,16
36,49,81
```
Transcribed Image Text:### Task 1: Arrays and Pointers For this task, you are required to provide files called `arrP.cpp` as well as a makefile to compile and run it. In your file, `arrP.cpp`, you should have a skeleton of a main program as per normal which you will then fill in as per the following. The objective of this task is to demonstrate the use of pointers for creating dynamic arrays. Specifically, through the use of pointers, it is possible to create arrays of a dynamic size. That is, to create an array of a specific size that can be altered as needed. The type should be integer. Your program will need to read from a file called `values.txt`. This file has the following format: ``` 4;1,2,3,4 3;6,7,9 ``` The above refers to a line with two components: size and the values of an array. The first number before the semi-colon, refers to the size of the array. What follows afterwards are the values that should go in that array. The number of lines you will have to read is not specified. You will read from this file, line by line, each of the lines, and then store the values in the array. Then the following operation should be done: - **If the largest element in the array is odd**, square every value in the array and display the array, as a single comma delimited line with a new line at the end. - **If the largest element in the array is even**, multiply every value by the largest value in the array and display the array, as a single comma delimited line with a new line at the end. An example of the output given the above file would be: ``` 4,8,12,16 36,49,81 ```
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education