Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be:
from a previous program, populations and the associated flowrates for those populations (an int array of populations and a double array of the associated flowrate)
a series of values and the square roots of those integers (an int array of values and a double array of associated square roots)
a series of values and an indication of whether or not each value is odd or even (an int array and a bool array)
1. Declare and initialize a constant to represent the size of both arrays (at least 10 positions)
2. Declare and initialize your first array
3. Declare and initialize your second array, based on the data in your first array
4. Output the contents of both arrays in neat columns with headers
Optional suggestions (good to do, not required) 1. Try to break your program up into different functions 2. Use user input to initialize the first array
Use this code as a guide;
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
#define PI 3.14159265
const int ARRAY_SIZE = 25;
void initializeArray(double arr[], int size);
void printArrays(int arrOne[], double arrTwo[], int size);
int main(int argc, char *argv[])
{
int arrayOne[ARRAY_SIZE];
double arrayTwo[ARRAY_SIZE];
int index;
for (index = 0; index < ARRAY_SIZE; index++)
{
arrayOne[index] = index + 1;
}
initializeArray(arrayTwo, ARRAY_SIZE);
printArrays(arrayOne, arrayTwo, ARRAY_SIZE);
cin.ignore();
cin.get();
}
void initializeArray(double arr[], int size)
{
for (int index = 0; index < size; index++)
{
arr[index] = cos((index+1) * PI / 180);
}
}
void printArrays(int arrOne[], double arrTwo[], int size)
{
cout << setw(6) << "degree" << setw(10) << "cosine" << endl;
for (int index = 0; index < size; index++)
{
cout << setw(3) << arrOne[index] << setw(14) <<
arrTwo[index] << endl;
}
}
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int ARRAY_SIZE = 20;
void initializeArray(bool arr[], int size);
void printArrays(int arrOne[], bool arrTwo[], int size);
int main(int argc, char *argv[])
{
int arrayOne[ARRAY_SIZE];
bool arrayTwo[ARRAY_SIZE];
int index;
for (index = 0; index < ARRAY_SIZE; index++)
{
arrayOne[index] = index + 1;
}
initializeArray(arrayTwo, ARRAY_SIZE);
printArrays(arrayOne, arrayTwo, ARRAY_SIZE);
cin.ignore();
cin.get();
}
void initializeArray(bool arr[], int size)
{
for (int index = 0; index < size; index++)
{
// compute even or odd using % operator
// where a%b returns reminder after dividing a by b
arr[index] = index%2;
}
}
void printArrays(int arrOne[], bool arrTwo[], int size)
{
cout << setw(6) << "NUMBER" << setw(10)
<< "EVEN\?" << endl;
cout << "----------------"<< endl;
for (int index = 0; index < size; index++)
{
cout << setw(3) << arrOne[index]<<setw(12);
//formatting output from 1 or 0 to words true or false
respectively
if(arrTwo[index]==1){
cout<<" True";
}
else{
cout<<" False";
}
cout<<endl;
}
cout << "----------------"<< endl;
}
COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
Code
#include <iostream>
#include <string>
#include<iomanip>
using namespace std;
const int ARRAY_SIZE = 10;
void initializeFirstArray(int arr[]);
void initializeSeondArray(int arry[], bool isPrime[]);
void printArrays(int arrOne[], bool arrTwo[]);
bool isPrime(int);
int main()
{
int arrayOne[ARRAY_SIZE];
bool primeCheck[ARRAY_SIZE];
initializeFirstArray(arrayOne);
initializeSeondArray(arrayOne,primeCheck);
printArrays(arrayOne,primeCheck);
}
void initializeFirstArray(int arr[])
{
for(int i=0;i<ARRAY_SIZE;i++)
{
cout<<"Enter a intger : ";
cin>>arr[i];
}
}
void initializeSeondArray(int arryInt[], bool prime[])
{
for(int i=0;i<ARRAY_SIZE;i++)
{
if(isPrime(arryInt[i]))
prime[i]=true;
else
prime[i]=false;
}
}
bool isPrime(int a)
{
for(int i=2;i<a/2;i++)
if(a%i==0)
return false;
return true;
}
void printArrays(int arrOne[], bool arrTwo[])
{
cout << setw(6) << "NUMBER" << setw(10) << "Prime\?" << endl;
cout << "----------------"<< endl;
for (int index = 0; index < ARRAY_SIZE; index++)
{
cout << setw(3) << arrOne[index]<<setw(12);
//formatting output from 1 or 0 to words true or false respectively
if(arrTwo[index]==1)
{
cout<<" True";
}
else
{
cout<<" False";
}
cout<<endl;
}
cout << "----------------"<< endl;
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Write a program that works with two arrays of the same size that are related to...
a) Hand-trace the following program and determine and write down what is the output of the code. b) Run the code and compare the program output to your hand-traced result obtained from part (a). #include <iostream> #include <iomanip> using namespace std; void f(); int x = 5; int main() { cout << "x = " << x << endl; int x = 6; cout << "x = " << x << endl; { int...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
/* * Program5 for Arrays * * This program illustrates how to use a sequential search to * find the position of the first apparance of a number in an array * * TODO#6: change the name to your name and date to the current date * * Created by Li Ma, April 17 2019 */ #include <iostream> using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() {...
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
Write a C++ program that contains 2 functions. LastLargestIndex, that takes as paraneters an int array and // its size and returns the index of the first occurrence of the largest element II in the array. Also, write a function to display the array #include ·peh.h" #include <iostream> using namespace std const int ARRAY_SIZE = 15; int main int list[ARRAY SIZE56, 34, 67, 54, 23, 87, 66, 92. 15, 32, 5, 54, 88, 92, 30 cout < List elements: "...
Q2. Consider the following C++ program that declares, allocates and fills in a1D array with random numbers between 0 and 100. The array is sent to a function that finds the indices of all items > 50. A new array is created and the indices are stored inside it. The size of the new arrays MUST BE the same as the number of items > 50. The function returns the new array which is then printed out by main. Here...
(C++ program )Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to the element 1 of the new array. Element 1 of the argument array should be copied to element 2 of the new array, and so forth....
c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...
When running the program at the destructor an exception is being thrown. Can someone help me out? vararray.h: #ifndef VARARRAY_H_ #define VARARRAY_H_ class varArray { public: varArray(); // void constructor int arraySize() const { return size; } // returns the size of the array int check(double number); // returns index of element containg "number" or -1 if none void addNumber(double); // adds number to the array void removeNumber(double); // deletes the number from the array ...
Question 1) Suppose a program has the following code: const int X = 2, Y = 3; int sum; int values[X][Y] = {{1, 2, 3}, {4, 5, 6}}; for(int i=0; i<X; i++) { sum=0; for(int j=0; j<Y; j++) sum+=values[i][j]; cout<<sum<<endl; } What is this program getting the sum of? Group of answer choices D-) The columns of the 2D array C-) The rows of the 2D array A-) All of the elements of the 2D...