Question

Problem 1: Complete separately Dr. Rocklino a) Write a program in which the main method creates two arrays, each with 10 intPlease help :)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Part a // Here is the code for Part a

======================================================================

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

void copy_to(int original[], int copied[]);
void copy_to(int original[], int copied[]) {
for(int i=0; i<10; i++) {
copied[i]=original[i];
}
}

int main() {

int original[10];
int copied[10];
for(int i=0; i<10; i++) {
original[i]= rand()%10;
}
copy_to(original,copied);
cout<<endl<<"Copied from Array:"<<endl;
for(int i=0; i<10; i++) {
cout<<original[i]<<" ";
}
cout<<endl<<"Copied to Array:"<<endl;
for(int i=0; i<10; i++) {
cout<<copied[i]<<" ";
}


}
======================================================================

=====================================================================

// Here is the code for Part B

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

int* append(int first[], int second[]);
int* append(int first[], int second[]) {
int aa[15];
for(int i=0; i<5; i++) {
aa[i]=first[i];

}
for(int i=0; i<10; i++) {
aa[5+i]=second[i];
}
return aa;
}

int main() {

int first[5];
int second[10];
int *aa;
for(int i=0; i<5; i++) {
first[i]= rand()%10;
}
for(int i=0; i<10; i++) {
second[i]= rand()%10;
}
aa=append(first,second);
cout<<endl<<"First Array:"<<endl;
for(int i=0; i<5; i++) {
cout<<first[i]<<" ";
}
cout<<endl<<"Second Array:"<<endl;
for(int i=0; i<10; i++) {
cout<<second[i]<<" ";
}

cout<<endl<<"Appended Array:"<<endl;
for(int i=0; i<15; i++) {
cout << *(aa + i) <<" "<< endl;
}


}
========================================================================================

Add a comment
Know the answer?
Add Answer to:
Please help :) Problem 1: Complete separately Dr. Rocklino a) Write a program in which the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2) Write a complete program in which main creates two Integer arrayLists and then adds 1,...

    2) Write a complete program in which main creates two Integer arrayLists and then adds 1, 2, , 10 to the first ArrayList, and 21, 22, ^, 30 to the second ArrayList. main should call a method passing it the two ArrayLists. This method should create and return a third ArrayList, each slot of which contains the sum of the values in the corresponding slots of the first and second ArrayLists. On return to main, main should display the values...

  • Write a complete Java program called MethodTest according to the following guidelines. The main method hard-codes...

    Write a complete Java program called MethodTest according to the following guidelines. The main method hard-codes three integer values into the first three positions of an array of integers calls a method you write called doubleEachValue that takes an array of integers (the one whose values you hard-coded in main) as its only argument and returns an ArrayList of integers, with each value in returned ArrayList equal to double the correspondingly indexed value in the array that is passed in...

  • Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array...

    Write a Java program in Eclipse. . Write a Java program that: 1. Creates an array of 100 integers. Initialize the array to have all zeros. 2. Puts even numbers starting from 6 (excluding multiples of 12) into the first 50 slots of the array above. So numbers 6,8,10,14,16,18,20,22,26, etc. go into the first 50 positions in the array. Print the array. 3. Puts random numbers between 45 and 55 into the second 50 slots of the array above (second...

  • In java, write method, shuffle, which accepts an array of int, creates a copy of the...

    In java, write method, shuffle, which accepts an array of int, creates a copy of the formal parameter, shuffles the copy, then returns the copied, shuffled array, leaving the formal parameter unchanged. Shuffling is a process of swapping each element of array with another element randomly chosen from the array. For testing the shuffle method have main call shuffle, repeatedly having it shuffle its previously returned array until the returned (shuffled) array is identical (equal) to the original array that...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • Write a complete JAVA program to do the following program. The main program calls a method...

    Write a complete JAVA program to do the following program. The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...

  • Please answer in C++, and Please consider ALL parts of the question, especially where it asks the...

    Please answer in C++, and Please consider ALL parts of the question, especially where it asks the user for V. So there should be a "cin >> V" somewhere. The last guy did not answer it correctly so please make sure you do! Thank You!! Question 1 Write the following two functions. The first function accepts as input a two-dimensional array of integers. It returns two results: the sum of the elements of the array and the average The second...

  • Can you please answer this in complete C++ program. I. Write a program that reads in...

    Can you please answer this in complete C++ program. I. Write a program that reads in an array of five integers al 5] and arses the mray in t fncion largest that rcurns the value of the largest element in the arrav, 2.Write a program that reads in two arrays, a[3] and b[3], and passes them to a function Scalarproduct that returns the scalar product of these arrays; the scalar product of two arrays is

  • Please write a C# program For this part of the lab, you'll be writing methods to...

    Please write a C# program For this part of the lab, you'll be writing methods to work with 1D arrays. We will expect you to know how to create an array, and store and retrieve information from them. Continue working in the same project and “Program.cs” file. You will be generating random numbers, but the class Random is part of the standard library (don’t need any additional using statements). You should consider developing the methods for this project incrementally. In...

  • c++ show code thanks, only use library <iostream> Question 1 Write the following two functions The...

    c++ show code thanks, only use library <iostream> Question 1 Write the following two functions The first function accepts as input a two-dimensional array of integers. It returns two results: the sum of the elements of the array and the average The second function accepts as input a two-dimensional array of integers and integer value V. It returns true if the value V is found in the array, false otherwise. Write a main program that declares and initializes the following...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT