1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bija089 [108]
3 years ago
10

Consider a company that needs to sort an array of structures of type Customer by balance, with the largest balance first. Here i

s the definition of the Customer structure: struct Customer { string name ; double balance ; } In real life the Customer array may have thousands of data members and occupy a large area of memory, making it computationally expensive to move Customer objects around while sorting . In this problem, you will create an array of only 10 structures, say Customer data[10]. You also can define an auxiliary array Customer *pData[10], setting each entry of pData [k] to point to the corresponding entry of data[k]. Write a program that sorts the array of pointers so that when you go through pData in increasing order of index k, the entries pData[k] point to Customer objects in decreasing order by balance, meaning that pdata[0] now points to the customer with the highest balance, and pData[9] points to the customer with the smallest balance.
Computers and Technology
1 answer:
8090 [49]3 years ago
4 0

Answer:

#include <iostream>

#include <string>

#include <cstring>

#include <cstdlib>

using namespace std;

struct Person

{

string name;

int age;

};

int main()

{

struct Person data[10];

struct Person *pData[10],*temp;

string names[] = {"a","b","c","g","z","l","p","q","r","w"};

int num[] = {4,6,34,8,13,90,33,22,18,23};

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

{

data[i].name = names[i];

data[i].age = num[i];

pData[i] = &data[i];

}

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

{

for(int j=i+1;j<9;j++)

{

if(pData[i]->name.compare(pData[j]->name)>0)

{

temp = pData[i];

pData[i] = pData[j];

pData[j] = temp;

}

}

}

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

{

cout<<pData[i]->name<<" "<<pData[i]->age<<endl;

}

}

Explanation:

The line #include <iostream> initializes the program.

This program created an array of only 10 structures, Customer data. Also defined an auxiliary array Customer *pData.

The program uses these parameters to sorts the array of pointers so that when you go through pData in increasing order of index k, the entries pData[k] point to Customer objects in decreasing order by balance, meaning that pdata[0] now points to the customer with the highest balance, and pData[9] points to the customer with the smallest balance.

You might be interested in
1. Which mechanical part or feature listed in the section on Critical Vehicle Systems do you think is most important?
kaheart [24]
I think it would be seatbelt but is it a multiple choice if so what's the choices
3 0
4 years ago
Read 2 more answers
Which of the following is a good design tip.
tia_tia [17]

Answer:

Offer as much extraneous information as possible. The viewer will decide what is important.

5 0
3 years ago
Given that add, a function that expects two integer parameters and returns their sum, and given that two variables, euro_sales a
Evgesh-ka [11]

Answer:

int eurasia_sales = add(euro_sales,asia_sales);

Explanation:

Kindly find the explanation attached

Download txt
7 0
4 years ago
Jacinta registered herself on a social-networking site. She receives one or two emails every day about promotional offers as wel
Rainbow [258]
It would be Spam. . . . 

3 0
4 years ago
A picture in electronic form<br> h
Marysya12 [62]

Answer:

Image editing software. refers to computer programs that allow you to create and modify digital images, or pictures in the electronic form. Digital images.

5 0
3 years ago
Other questions:
  • To pinpoint an earthquake's location, scientists need information from how many seismometers?
    8·1 answer
  • Me2540 week 5 assignment<br> what do i want to know?
    9·1 answer
  • Women make up 52 percent of the voting-age population and are more likely to vote, yet
    12·2 answers
  • Dereck works for long hours on his computer. He frequently experiences physical strain by the end of the day because he does not
    8·2 answers
  • which is the quickest way to change the font color in multiple, randomly located cells in a worksheet?
    6·2 answers
  • Which of the following statements is false? The ARPANET is the precursor to today’s Internet. Today’s fastest Internet speeds ar
    11·1 answer
  • Number of frames displayed per second
    15·1 answer
  • the id selector uses the id attribute of an html element to select a specific element give Example ?​
    11·1 answer
  • HELLLLLLLLLLLLLLLLLLLLP PLSSSSSSSSSSS HELLLLLLLLLP
    14·1 answer
  • Which validation check can be used on the following data. "XX000" 
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!