Define a function that works with c-style arrays of integers. The function should be called subtract and it should pass in 2 arrays and a single integer n. The function should change the first n value. the first array to be the difference between the first n values in the first array passed in and the first n values in the second array passed i

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
In cpp
Program Specifications
Define a function that works with c-style arrays of integers.
The function should be called subtract and it should pass in 2 arrays and a single integer n. The function should change the first n values in
the first array to be the difference between the first n values in the first array passed in and the first n values in the second array passed in.
For example, if the arrays passed in to subtract originally stores the values
1 2 3 45 6
0 1 2 3 4 5 6 7 8 9
and the integer passed in is 4 then after the function call the arrays would store the values
1 1 1 1 5 6
0 1 2 3 45 678 9
In the main function:
• Read in integer values from cin and store them in the first array until the user enters a -1.
• Now read in integer values from cin and store them in the second array until the user enters a -1 again.
• Now read in the single integer (the number of values that will be subtracted).
• Output the values in both arrays each array on their own line, each value in an array separated by a space
• Call the subtract function.
Output the values in the arrays again showing that array1 has been changed but array 2 has not
Do not prompt the user for input. Just read the values in to the array. You may assume there will never be more than 50 integers read in.
You may NOT use the vector class or the array class at all, only the c-style arrays you used in lab 5
Transcribed Image Text:Program Specifications Define a function that works with c-style arrays of integers. The function should be called subtract and it should pass in 2 arrays and a single integer n. The function should change the first n values in the first array to be the difference between the first n values in the first array passed in and the first n values in the second array passed in. For example, if the arrays passed in to subtract originally stores the values 1 2 3 45 6 0 1 2 3 4 5 6 7 8 9 and the integer passed in is 4 then after the function call the arrays would store the values 1 1 1 1 5 6 0 1 2 3 45 678 9 In the main function: • Read in integer values from cin and store them in the first array until the user enters a -1. • Now read in integer values from cin and store them in the second array until the user enters a -1 again. • Now read in the single integer (the number of values that will be subtracted). • Output the values in both arrays each array on their own line, each value in an array separated by a space • Call the subtract function. Output the values in the arrays again showing that array1 has been changed but array 2 has not Do not prompt the user for input. Just read the values in to the array. You may assume there will never be more than 50 integers read in. You may NOT use the vector class or the array class at all, only the c-style arrays you used in lab 5
Expert Solution
Introduction

Pass arrays by reference and iterate till passed value of times

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Transmission media
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.
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