Question

In: Computer Science

Write a program in which, you define and call each of the following functions, note that...

Write a program in which, you define and call each of the following functions, note that YOU CANNOT USE ARRAY NOTATION IN ANY FUNCTION AT ALL IN THIS EXERCISE, ONLY USE POINTER NOTATION TO MANIPULATE ARRAYS IN THE FUNCTIONS:

1. function read_array, that takes an array of 6 doubles and prompts the user to fill it through the keyboard.

2. function reverse_array, that takes an array of 6 doubles and reverses its contents.

3. function swap_arrays, that takes two arrays of type double and swaps their contents.

4. function print_array, that prints an array of 6 doubles.

5. call all these functions properly in your main program.

Solutions

Expert Solution

#include <iostream>
#define SIZE 6
using namespace std;
void read_array (double *);
void print_array (double *);
void reverse_array (double *);
void swap_array (double *, double *);
int
main ()
{
  double a[SIZE], b[SIZE];
  cout << "Enter first array :";
  read_array (a);
  cout << "First array is :";
  print_array (a);
  reverse_array (a);
  cout << "\nFirst array after calling reverse_array() :";
  print_array (a);
  cout << "\nEnter second array :";
  read_array (b);
  cout << "Second array is :";
  print_array (b);
  cout << "\nBefore calling swap_array(),";
  cout << "\nFirst array is :";
  print_array (a);
  cout << "\nSecond array is :";
  print_array (b);
  swap_array (a, b);
  cout << "\nAfter calling swap_array(),";
  cout << "\nFirst array is :";
  print_array (a);
  cout << "\nSecond array is :";
  print_array (b);
  return 0;
}

void
read_array (double *a)
{

  for (int i = 0; i < SIZE; i++)
    cin >> *(a + i);
}

void
print_array (double *a)
{
  for (int i = 0; i < SIZE; i++)
    cout << *(a + i) << ", ";

}

void
reverse_array (double *a)
{
  for (int i = 0; i < SIZE / 2; i++)
    {
      double temp = *(a + i);
      *(a + i) = *(a + SIZE - 1 - i);
      *(a + SIZE - i - 1) = temp;
    }

}

void
swap_array (double *a, double *b)
{
  for (int i = 0; i < SIZE; i++)
    {
      double temp = *(a + i);
      *(a + i) = *(b + i);
      *(b + i) = temp;
    }

}


Related Solutions

Part 1 Write a C++ program in which you define the following logical functions: 1) contradictory...
Part 1 Write a C++ program in which you define the following logical functions: 1) contradictory function (¬?) 2) logical and (? ∧ ?) 3) logical inclusive or (? ∨ ?) 4) implication function (? → ?) 5) biconditional (? ↔ ?) 6) logical exclusive or (? ⨁ ?) You can find the logical definitions for the above functions as given by Bertrand Russell in your text. You need to write a method (function) for each corresponding logical function. The...
Write a program call FancyMyName which asks you to write a program that tests the usage...
Write a program call FancyMyName which asks you to write a program that tests the usage of different methods for working with Strings. This program will ask the user to enter their first name and their last name, separated by a space. Read the user's response using Scanner. Separate the input string up into two strings, one containing the first name and one containing the last name. You can accomplish this by using the indexOf() hint*** find the position of...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt the user to enter the sales amount and computes and prints with a description the commission paid to salesperson as follows: 10% for sales amount less than $2,000.00, 15% for sales amount less than $10,000.00 and 20% for sales amount less than $20,000.00, then function calc_commission calls another function name assign_base_salary() to ask the user to enter each of 5 salesperson’s base salary ,...
Write a C program with call to functions to produce the output given below. // the...
Write a C program with call to functions to produce the output given below. // the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way: 1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call. 2) intList.h This file would have the IntNode...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O,...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated...
Recursion practice Write a Java program with functions for each of the following problems. Each problem...
Recursion practice Write a Java program with functions for each of the following problems. Each problem should be solved by writing a recursive function. Your final program should not have any loops in it. All of your solutions should be in a single .java file. The main function of the file should demonstrate each of your solutions, by running several tests and producing the corresponding outputs. Write a recursive method to 1. calculate power of a give number 2. multiply...
write C++ program using functions (separate function for each bottom) Write a program to find if...
write C++ program using functions (separate function for each bottom) Write a program to find if a number is large word for two given bottom base - bottom1 and bottom2. You can predict that a number, when converted to any given base shall not exceed 10 digits. . the program should ask from user to enter a number that it should ask to enter the base ranging from 2 to 16 after that it should check if the number is...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the...
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (forget-n L1 N) that returns the elements of L1 except for the first N. If N is negative, return all elements. If N exceeds the length of L1 return the empty list....
You must write each of the following scheme functions. You must use only basic scheme functions...
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem needs to use DrRacket software. Racket Language. Write a function (indices L1 X) that takes a list of elements L1 and an element X. The function returns a list of the indices in L1 that contain X. See the following examples for clarification....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT