Indirect Sorting Through Pointers #1
Consider a company that needs to sort an array Person data[10] of structures of type Person by name.
struct Person
{
string name;
int age;
}
In real life the Person structures may have many members and occupy a large area of memory, making it computationally expensive to move Person objects around while sorting. You can define an auxiliary array Person *pData [10], setting each entry of pData[k] to point to the corresponding entry of data[k]. Write a
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (6th Edition)
C++ How to Program (10th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Absolute Java (6th Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
- (Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard into an array named grade. The grades are to be counted as they’re read, and entry is to be terminated when a negative value has been entered. After all grades have been input, your program should find and display the sum and average of the grades. The grades should then be listed with an asterisk (*) placed in front of each grade that’s below the average. b. Extend the program written for Exercise 1a to display each grade and its letter equivalent, using the following scale: Between90and100=AGreaterthanorequalto80andlessthan90=BGreaterthanorequalto70andlessthan80=CGreaterthanorequalto60andlessthan70=DLessthan60=Farrow_forwardReverse ArrayWrite 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 reversedin the copy. The function should return a pointer to the new array. Demonstrate thefunction in a complete program.arrow_forwardTwo dimension array in C:Create a two dimension array of integers that is 5 rows x 10 columns.Populate each element in the first 2 rows (using for loops) with the value 5.Populate each element of the last three rows (using for loops) with the value 7.Write code (using for loops) to sum all the elements of the first three columns and output thesum to the screen. without using #definearrow_forward
- Kotlin Programming Array Exercise Create a Kotlin program that can print a specified element in an array given the code below: fun main(){ val pets=arrayOf("dog","cat","bird") for(element in pets){ println(element + " ") } } Thanks for answer I need it now how do we print the 2nd element?arrow_forwardC++ code not Javaarrow_forwardObjective: Design a program that uses two-dimensional arrays, classes and objects Assignment: Write a program that plays a tic-tac-toe game with the user. Define a class TicTacToe with the necessary data and functions to play the game. Use a 2-D char array with three rows and three columns as the game board. The class should also have the following functions: A constructor to initialize the board. I suggest either asterisk ('*') or characters '1' through '9'. A function to play the user's turn, fill in the board with either an 'X' or 'O' given row and column number (1-3) A function to play the computer's turn. This function will determine the row and column number to be filled in. You can use a simple algorithm such as look for the first space available, or random number generation. Complex AI algorithms will only be accepted with an explanation of its behavior via a zoom meeting. A function to verify if there is a win. This can be broken down by calling 3 separate private…arrow_forward
- // New Function prototypes void showValues(const int *, int); // display 10 numbers in a line from the array void fillArray(int *, int, int, int); // fill out random numbers between low and high into the array bool searchValue(const int *, int, int); // search value from the array void sortArray( int *, int); //sort the array in an ascending order void swap(int *, int *); //swap the values Modify the code below to create 50 random numbers instead of 10 and use the above new function protoypes. In the output, remove the display of the minimum, maximum and average from the array. Modify the showValues() function to display 10 numbers in a line from the array. [Part 2] Add the two functions to sort an array in an ascending order: void sortArray(int*, int); //ascending ordervoid swap(int*, int*); In the sortArray() function called the swap() function to swap the values from two elements in the array. Code: #include <iostream>#include <iomanip>#include…arrow_forwardEffects on Size and PaddingA flexible array member is treated as having no size when calculating the size of a structure, though paddingbetween that member and the previous member of the structure may still exist:/* Prints "8,8" on my machine, so there is no padding. */printf("%zu,%zu\n", sizeof(size_t), sizeof(struct ex1));/* Also prints "8,8" on my machine, so there is no padding in the ex2 structure itself. */printf("%zu,%zu\n", sizeof(struct ex2_header), sizeof(struct ex2));/* Prints "5,8" on my machine, so there are 3 bytes of padding. */printf("%zu,%zu\n", sizeof(int) + sizeof(char), sizeof(struct ex3));The flexible array member is considered to have an incomplete array type, so its size cannot be calculated usingsizeof.arrow_forwardC++ solvearrow_forward
- C languagearrow_forwardJavaarrow_forwardPointers with Arrays and Function Please use C Language to code 1. Write a program that accepts the blood pressure as a floating point value into a five- element array, called bp. The program has a module that uses pointer notation called hbp that checks whether the patients' blood pressure is high or normal. hbp has a pointer called bpPtr and an integer called arrsize has its arguments. The blood pressure of the patient is high if it is greater than 1.6 otherwise, it is normal.The module outputs to the patient that they have high blood pressure and that they are to monitor their cholesterol levels over the next 7 days; otherwise, it outputs a message that the blood pressure level is normal.arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning