Question

please use c++ language 1. Request three different integers from the console. a) Write a swap...

please use c++ language

1. Request three different integers from the console.

  1. a) Write a swap function that swaps two integer values.

  2. b) Write a sort function which accepts three integers as input then sorts

    them from largest to smallest using the swap function.

  3. c) Output the integers before and after sorting.

Example 1 Output (input in bold italics)

Enter three different integers: 3 2 4

3 2 4
4 3 2

Example 2 Output (input in bold italics)

Enter three different integers: 15 23 63

15 23 63
63 23 15

Code a swap function not using c++ library function.

2. Implement an array of the English alphabet (26 characters).

a) Use a loop and casting to generate the array.
b) Output the array.
c) Create a swap function for swapping character variables.
d) Use a loop and the swap function to reverse all array elements. e) Output the updated array.

Hint: Set a variable for the first and last indices. Swap those values. Gradually move the first/last pointers to the middle of the array, swapping as you go. When the middle is reached, the array will be reversed.

Example Output (input in bold italics)
Original: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Reversed: Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

please use c++ language using arrays only and a swap code function using upstream

3.

3. Randomly generate a partially filled array of unique values.

  1. a) Create a blank partially filled integer array of capacity 10.

  2. b) Implement an array output function.

  3. c) Implement a hasElement function which accepts the array and an integer

    element as input. It checks the array for the element and returns true

    if the element exists, false if it does not.

  4. d) Implement a randArray function which populates the array with random

    integers between 0 and 9 inclusive. This function should use the

    hasElement function to ensure all elements are unique (no duplicates).

  5. e) Output the array. Confirm that all values (0-9) are included.

Example 1 Output (input in bold italics)

2 5 8 9 3 4 0 1 7 6
Example 2 Output (input in bold italics)

5 9 3 4 7 0 1 6 2 8

using iostream and srand time.h c++

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

1)

#include <iostream>
using namespace std;

void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}

void sort(int *a, int *b, int *c)
{
if(a < b)
swap(a, b);
if(a < c)
swap(a, c);
}

int main() {
int a, b, c;
cout << "Enter three different integers: ";
cin >> a >> b >> c;
  
cout << a << " " << b << " " << c << endl; // printing before call
sort(&a, &b, &c);
cout << a << " " << b << " " << c << endl; // printing after call
  
}

// -- One question at a time please - Policy of Chegg

Add a comment
Know the answer?
Add Answer to:
please use c++ language 1. Request three different integers from the console. a) Write a swap...
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
  • Request an integer n from the console. Write a function that accepts n as input and...

    Request an integer n from the console. Write a function that accepts n as input and outputs the multiplication table of n from 1 to n to the console. Example Output (input in bold italics) Enter an integer: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9...

  • C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array...

    C++ 3. Random modification of all elements in an integer array. a) Initialize an integer array of capacity 5. b) Implement an array output function. c) Output the array to console. d) Implement an offset function that accepts an integer array as input and randomly modifies each element by +/- 5. e) Use the offset function to update the array. f) Output the modified array. Example Output (input in bold) Original: 5 1 4 9 2 Offset: 7 -2 6...

  • 1. Request a 3-digit integer from the console. Use division and modulo operations to extract each...

    1. Request a 3-digit integer from the console. Use division and modulo operations to extract each digit in reverse order. For each digit, determine if it is a factor of the original integer. Example Output (input in bold italics) Enter a 3-digit integer: 543 Is 3 a factor of 543? 1 Is 4 a factor of 543? 0 Is 5 a factor of 543? 0 c++ language

  • 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments

    9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values should be reversed in the copy. The function should return a pointer to the new array. Demonstrate the function by using it in the main program that reads an integer N  (that is not more than 50) from standard input and then reads N  integers from a file named...

  • Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program...

    Use c++ as programming language. The file needs to be created ourselves (ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

  • Python DESCRIPTION Write a program that will read an array of integers from a file and...

    Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....

  • daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function....

    daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function. Description Create a project called Daily21. Add a source file called daily21.c into the project. In this exercise, you will practice working with an array of integers. In the main function, you first need to create an integer array with 10 elements in t. Use a loop to read 10 integers from the user and store the values to the array (in the order...

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • C++ 3. Write a program that recursively calculates n factorial (n!) a) Main should handle all...

    C++ 3. Write a program that recursively calculates n factorial (n!) a) Main should handle all input and output b) Create a function that accepts a number n and returns n factorial c) Demonstrate the function with sample input from console. n! n * n-1 * n-2 * n-3, for all n > 0 For example, 3!-3 21-6 using a recursive process to do so. Example output (input in bold italics) Enter a number: 5 5120

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