Question

CSCI 40 Computer Programming Methodology I Assignment 16 Part l Write a program that declares a two dimensional array and initialize it with following integers 2 4 3 81 45 2 10 3 6 20 21 12 28-5 7 11 2 4 75041 8 5 -10 3 2 0 Then 1. Write statements that display all the numbers in the array 2. Write statements that calculate and display the sums of the numbers in each row 3. Write statements that calculate and display the smallest number in the array (Here calculate means using looping statements to find the smallest number in the array) Part II (Optional for extra credit) Write a function that receives an integer array, the length of the array, an integer for indicating the position, an integer for insertion) and returns a Boolean value (True or False). Using following function header. bool insert (int a],int length, int position, int item) The function will shift all the numbers from position in the array to the right by one place and replace the number in the position by item If position > length or position1 the function returns false, otherwise the function returns true For example, if the function receives following array: myArrayl7]-(1,2,3,4,5,6,7), and position-3, item=100, then after the function call, the array would be containing following numbers: (1,2,100,3,4,5,6]

Need Part 1 and Part 2 please! also has to build and run, thank you!

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

Hi friend, I have answered Part 2.
pelase repost other in separate post.

#include <iostream>

using namespace std;

bool insert(int a[], int length, int position, int item) {

if(position > length || position < 1)

return false;

// shofting all elements from position-1 to right by one

for(int i=length-1; i>=position; i--)

a[i] = a[i-1];

a[position-1] = item;

return true;

}

void printArray(int a[], int length) {

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

cout<<a[i]<<" ";

cout<<endl;

}

int main() {

int a[] = {1,2,3,4,5,6,7};

printArray(a, 7);

insert(a, 7, 3, 100);

printArray(a, 7);

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Need Part 1 and Part 2 please! also has to build and run, thank you! CSCI...
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
  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • 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...

  • Write a C++ program that does the following : 1. Accepts array size from the keyboard....

    Write a C++ program that does the following : 1. Accepts array size from the keyboard. The size must be positive integer that is >= 5 and <= 15 inclusive . 2. Use the size from step 1 in order to create an integer array. Populate the created array with random integer values between 10 and 200. 3. Display the generated array. 4. Write a recursive function that displays the array in reverse order . 5. Write a recursive function...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

    This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the...

  • c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input:...

    c++ #include <iostream> #include <string> using namespace std; /* Write a function checkPrime such that input: an int output: boolean function: Return true if the number is a prime number and return false otherwise */ //TO DO ************************************** /* Write a function checkPrime such that input: an array of int and size of array output: nothing function: Display the prime numbers of the array */ //TO DO ************************************** /* Write a function SumofPrimes such that input: an int output: nothing...

  • Need Help With The TODO Numbers Tools Configure Window Help Edit View Project Build Run BB9-...

    Need Help With The TODO Numbers Tools Configure Window Help Edit View Project Build Run BB9- Projectl_NumberCalculationsja... X public static void main(String[] args) Scanner input = new Scanner(System.in); int numberl; //first number int number2; //second number int number 3; //third number int largest; //largest value int smallest; // smallest value int sum // sum of numbers int product; //product of numbers int average: //average of numbers /* TODO#1: write a series of statements to read in three numbers and assign...

  • Document2 Tell me ign Layout References Mailings Review View 1. Write a program called Lab18C that...

    Document2 Tell me ign Layout References Mailings Review View 1. Write a program called Lab18C that searches for a number in an array. T a. Write a bool function named search that receives 3 parameters: an int array, an int containing the length of the array, and an int number to search for. Return true if the number is in the array and false otherwise. b. Write a void function called fillArray with the array as a parameter that uses...

  • 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...

  • 1. Write code for a function that receives two parameters (a,and b) by value and two...

    1. Write code for a function that receives two parameters (a,and b) by value and two more parameters (c and d) by reference. All parameters are double. The function works by assigning c to (a/b) and assigning d to (a*b). The function has no return value. From main, use scanf to get two numbers, then call the function, and then display both outcome values to the output in a printf statement. 2. After part 1 is completed, write code to...

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