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++ MPL
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Starting Out With Visual Basic (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
Database Concepts (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- (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_forwardKotlin 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_forward
- Objective: 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_forward
- c++ make a simple prrogram that takes random 2d array entered by user and organizes it use pointers for example if the user enter ((8,4),(3,4),(7,2),(8,6),(3,1)) no limit to number of sets use pointers there should be a function called transformer that will transform them into the right order and a funtion called display that will display what was inputed then it would organize it into ((4,8),(3,4),(2,7),(6,8),(1,3)) IT should only modify it and not make a copy of it.arrow_forwardC++ solvearrow_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
- PROGRAMMING LANGUAGE: C++ Write a program that accepts up to 20 test-match scores of a batsman in the range of 0 to 100 from the user and stores them in an array. Then main should report how many perfect scores (i.e., scores of 100) and ducks (i.e., scores of 0) were enteredarrow_forwardC++arrow_forwardC++ Coding Complete the 8 queens 2-dimensional array program with backtracking. Reminder:In the program, 0 in a cell indicates no queen in that cell, and 1 indicates the presence of a queen.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