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]
2 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]2 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
Which statement describes the relationship between science and technology?
Elden [556K]
Answer: science is the study of the world, and technology changes the world to solve problems.
3 0
2 years ago
Read 2 more answers
Trudy is preparing a reply to an email message. Before she could send out the message, she is called for a meeting. If Trudy has
Ronch [10]
Her Drafts folder. Hope this helped!
3 0
3 years ago
Read 2 more answers
Sub to the channel plz plz
Hunter-Best [27]

Answer:

um

Explanation:

6 0
2 years ago
Read 2 more answers
Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. End with a n
worty [1.4K]

Answer:

The program to this question as follows:

Program:

//header file

#include <iostream> //defining header file

using namespace std;

void printFeetInchShort(int numFeet,int numInches); //decalring method printFeetInchShort  

void printFeetInchShort(int numFeet,int numInches)//defining method printFeetInchShort

{

cout<<"height: "; // print message

cout<<numFeet<<"\'"<<""<<numInches<<"\""; //print value

}

int main() //defining main method

{

int numFeet, numInches; //defining integer variable

cout<<"Enter height feet: "; //print message

cin>>numFeet; //input value by user

cout<<"Enter height inches: "; //print message

cin>>numInches; //input value by user

printFeetInchShort(numFeet,numInches); //calling method printFeetInchShort    

return 0;

}

Output:

Enter height feet: 5

Enter height inches: 9

height: 5'9"

Explanation:

In the above C++ language program, first, a header file is included, that uses the basic function, in the next step, the "printFeetInchShort()" method is defined, in the method two integer variables passed as a parameter, inside this method a print function "cout" is used, that print user input value with single and double quote.

Then the main method is declared, inside this method two integer variables "numFeet and numInches" are defined, which is used to take input value by user and pass the value in "printFeetInchShort()" function parameter and call the function.

4 0
3 years ago
Read 2 more answers
To a traditional computer, one means
blagie [28]

a.on , off

In most computer processors, electron movement is controlled by tiny switches that turn this flow of electricity on and off...zero represents off and one represents on

4 0
3 years ago
Other questions:
  • Under what conditions might the Justice Department approve a merger between two companies that operate in an industry with a pos
    14·1 answer
  • Look act the picture
    5·1 answer
  • Which of the following events would most likely produce an earthquake
    7·1 answer
  • A cable that connects the computer to the printer is an example of<br> A.hardware<br> B.software
    13·2 answers
  • "In a web app, where is data usually stored? A. Mobile network B. Application storage C. Local computer D. Cloud storage"
    14·1 answer
  • Study the images of two different fronts.
    7·2 answers
  • 8. A sprite is a simple spider shaped thing with n legs coming out from a center point. The angle
    10·1 answer
  • You attempt to telnet to system 192.168.1.240. You receive the following message: "Connecting To 192.168.1.240...Could not open
    5·1 answer
  • ANSWER QUICKLY PLEASE
    7·1 answer
  • Write a pseudocode algorithm that prompts the user to enter a three-digit number and outputs the hundreds, tens and units.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!