Question

#include <iostream> #include <queue> #include <string> #include <vector> ...

#include <iostream>
#include <queue>
#include <string>
#include <vector>
#include <ctime>
#include <cstdlib>

using namespace std;
class information
{
public:
   string name;
   int month;
   int day;
   int year;
   int balance;
};

struct Comp {
   bool operator()(const information&a, const information &b) {
       if (a.year == b.year)
       {
           if (a.month == b.month)
           {
               return a.day > b.day;
           }
       }
       else
       {
           return a.year > b.year;
       }
   }
};

int main()
{
   information person[63];
   int RNG;
   person[0].name = "angel", person[0].month = 5, person[0].day = 8, person[0].year = 1996, person[0].balance = 30,
   person[1].name = "legna", person[1].month = 7, person[1].day = 5, person[1].year = 2000, person[1].balance = 40;
   person[2].name = "Martin", person[2].month = 4, person[2].day = 4, person[2].year = 1997, person[2].balance = 50;
   person[3].name = "Dominick", person[3].month = 2, person[3].day = 2, person[3].year = 1985, person[3].balance = 1436;
   person[4].name = "Juditch", person[4].month = 6, person[4].day = 25, person[4].year = 1967, person[4].balance = 6585;
   person[5].name = "Cheryl", person[5].month = 10, person[5].day = 20, person[5].year = 1971, person[5].balance = 1991;
   person[6].name = "Gina", person[6].month = 5, person[6].day = 5, person[6].year = 2010, person[6].balance = 4050;
   person[7].name = "Marco", person[7].month = 2, person[7].day = 24, person[7].year = 2004, person[7].balance = 4514;
   person[8].name = "William", person[8].month = 11, person[8].day = 9, person[8].year = 1989, person[8].balance = 5412;
   person[9].name = "Marjorie", person[9].month = 7, person[9].day = 26, person[9].year = 1985, person[9].balance = 6553;
   person[10].name = "Neal", person[10].month = 5, person[10].day = 8, person[10].year = 1961, person[10].balance = 1917;
   person[11].name = "Kathy", person[11].month = 10, person[11].day = 20, person[11].year = 1971, person[11].balance = 4396;
   person[12].name = "Pattie", person[12].month = 12, person[12].day = 5, person[12].year = 2007, person[12].balance = 159,
   person[13].name = "Darron", person[13].month = 8, person[13].day = 5, person[13].year = 1952, person[13].balance = 7694;
   person[14].name = "Meri", person[14].month = 4, person[14].day = 16, person[14].year = 1976, person[14].balance = 2436;
   person[15].name = "Mariann", person[15].month = 12, person[15].day = 7, person[15].year = 1966, person[15].balance = 3756;
   person[16].name = "Manuela", person[16].month = 1, person[16].day = 17, person[16].year = 1978, person[16].balance = 4011;
   person[17].name = "Angelita", person[17].month = 4, person[17].day = 30, person[17].year = 1944, person[17].balance = 1000;
   person[18].name = "Nida", person[18].month = 1, person[18].day = 16, person[18].year = 1980, person[18].balance = 7411;
   person[19].name = "Vanetta", person[19].month = 6, person[19].day = 3, person[19].year = 2013, person[19].balance = 7956;
   person[20].name = "Gussie", person[20].month = 9, person[20].day = 21, person[20].year = 1997, person[20].balance = 7113;
   person[21].name = "Jaymie", person[21].month = 10, person[21].day = 8, person[21].year = 1957, person[21].balance = 7936;
   person[22].name = "Mitsuko", person[22].month = 9, person[22].day = 6, person[22].year = 1960, person[22].balance = 177;
   person[23].name = "Shirly", person[23].month = 6, person[23].day = 12, person[23].year = 1946, person[23].balance = 1317;
   person[24].name = "Luvenia", person[24].month = 6, person[24].day = 10, person[24].year = 1950, person[24].balance = 30,
   person[25].name = "Minda", person[25].month = 7, person[25].day = 9, person[25].year = 1939, person[25].balance = 40;
   person[26].name = "Carlo", person[26].month = 3, person[26].day = 3, person[26].year = 1965, person[26].balance = 50;
   person[27].name = "Clotilde", person[27].month = 9, person[27].day = 25, person[27].year = 2013, person[27].balance = 1436;
   person[28].name = "Luci", person[28].month = 12, person[28].day = 10, person[28].year = 1944 , person[28].balance = 6585;
   person[29].name = "Agnus", person[29].month = 12, person[29].day = 16, person[29].year = 1937, person[29].balance = 1991;
   person[30].name = "Magdalen", person[30].month = 10, person[30].day = 30, person[30].year = 2006, person[30].balance = 4050;
   person[31].name = "Mariana", person[31].month = 5, person[31].day = 5, person[31].year = 2017, person[31].balance = 4514;
   person[32].name = "Billie", person[32].month = 5, person[32].day = 30, person[32].year = 1961, person[32].balance = 5412;
   person[33].name = "Walter", person[33].month = 7, person[33].day = 26, person[33].year = 1925, person[33].balance = 6553;
   person[34].name = "Vincent", person[34].month = 7, person[34].day = 10, person[34].year = 1961, person[34].balance = 1917;
   person[35].name = "Jeannette", person[35].month = 11, person[35].day = 20, person[35].year = 1933, person[35].balance = 4396;
   person[36].name = "Noah", person[36].month = 12, person[36].day = 13, person[36].year = 1973, person[36].balance = 159,
   person[37].name = "Julian", person[37].month = 5, person[37].day = 28, person[37].year = 2012, person[37].balance = 7694;
   person[38].name = "Guadalupe", person[38].month = 9, person[38].day = 16, person[38].year = 1921, person[38].balance = 2436;
   person[39].name = "Melanie", person[39].month = 9, person[39].day = 16, person[39].year = 1972, person[39].balance = 3756;
   person[40].name = "Ramon", person[40].month = 8, person[40].day = 20, person[40].year = 2007, person[40].balance = 4011;
   person[41].name = "Toby", person[41].month = 8, person[41].day = 25, person[41].year = 1993, person[41].balance = 1000;
   person[42].name = "Stella", person[42].month = 1, person[42].day = 16, person[42].year = 1980, person[42].balance = 7411;
   person[43].name = "Bruce", person[43].month = 5, person[43].day = 7, person[43].year = 1999, person[43].balance = 7956;
   person[44].name = "Copper", person[44].month = 12, person[44].day = 8, person[44].year = 2004, person[44].balance = 7113;
   person[45].name = "Barnett", person[45].month = 3, person[45].day = 21, person[45].year = 1958, person[45].balance = 7936;
   person[46].name = "Warner", person[46].month = 7, person[46].day = 23, person[46].year = 1987, person[46].balance = 177;
   person[47].name = "Dennis", person[47].month = 8, person[47].day = 30, person[47].year = 1984, person[47].balance = 1317;
   person[48].name = "Sarah", person[48].month = 6, person[48].day = 17, person[48].year = 1986, person[48].balance = 4349;
   person[49].name = "Jerry", person[49].month = 8, person[49].day = 4, person[49].year = 1968, person[49].balance = 6517;
   person[50].name = "Anna", person[50].month = 7, person[50].day = 8, person[50].year = 1951, person[50].balance = 2420;
   person[51].name = "Carl", person[51].month = 2, person[51].day = 25, person[51].year = 1950, person[51].balance = 2446,
   person[52].name = "Anthony", person[52].month = 3, person[52].day = 14, person[52].year = 1990, person[52].balance = 1528;
   person[53].name = "Bobby", person[53].month = 9, person[53].day = 14, person[53].year = 1951, person[53].balance = 3480;
   person[54].name = "Clarence", person[54].month = 3, person[54].day = 4, person[54].year = 2014, person[54].balance = 860;
   person[55].name = "Marilyn", person[55].month = 4, person[55].day = 15, person[55].year = 1998, person[55].balance = 7018;
   person[56].name = "Paul", person[56].month = 5, person[56].day = 28, person[56].year = 1939, person[56].balance = 6939;
   person[57].name = "Martin", person[57].month = 3, person[57].day = 14, person[57].year = 1920, person[57].balance = 4035;
   person[58].name = "Jean", person[58].month = 2, person[58].day = 7, person[58].year = 1934, person[58].balance = 7435;
   person[59].name = "Mary", person[59].month = 12, person[59].day = 25, person[59].year = 1952, person[59].balance = 4439;
   person[60].name = "Teresa", person[60].month = 10, person[60].day = 1, person[60].year = 1959, person[60].balance = 7867;
   person[61].name = "Andrea", person[61].month = 1, person[61].day = 11, person[61].year = 2005, person[61].balance = 2793;
   person[62].name = "Edward", person[62].month = 4, person[62].day = 14, person[62].year = 1924, person[62].balance = 2355;

   priority_queue<information, vector<information>, Comp> pq;
   srand(time(NULL));
   for (int i = 0; i < 10; i++)
   {
       RNG = rand() % (63 - 1) + 1;
       pq.push(person[RNG]);
   }

   while (!pq.empty())
   {
       information r = pq.top();
       pq.pop();
       cout << "Name = "<<r.name << " Month = " << r.month << " Day = " << r.day << " Year = " << r.year << " Balance = " << r.balance << endl;
   }
   system("Pause");
   return 0;
}

Can someone help me make my code better i am getting an error and i dont know how to fix it

c++

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

Below is your working c++ code :now it doesnt show any error

#include<iostream>
#include<string>
#include <queue>
using namespace std;

class information
{
public:
string name;
int month;
int day;
int year;
int balance;
};

struct Comp {
bool operator()(const information&a, const information &b) {
if (a.year == b.year)
{
if (a.month == b.month)
{
return a.day > b.day;
}
}
else
{
return a.year > b.year;
}
}
};

int main()
{
information person[63];
int RNG;
person[0].name = "angel", person[0].month = 5, person[0].day = 8, person[0].year = 1996, person[0].balance = 30,
person[1].name = "legna", person[1].month = 7, person[1].day = 5, person[1].year = 2000, person[1].balance = 40;
person[2].name = "Martin", person[2].month = 4, person[2].day = 4, person[2].year = 1997, person[2].balance = 50;
person[3].name = "Dominick", person[3].month = 2, person[3].day = 2, person[3].year = 1985, person[3].balance = 1436;
person[4].name = "Juditch", person[4].month = 6, person[4].day = 25, person[4].year = 1967, person[4].balance = 6585;
person[5].name = "Cheryl", person[5].month = 10, person[5].day = 20, person[5].year = 1971, person[5].balance = 1991;
person[6].name = "Gina", person[6].month = 5, person[6].day = 5, person[6].year = 2010, person[6].balance = 4050;
person[7].name = "Marco", person[7].month = 2, person[7].day = 24, person[7].year = 2004, person[7].balance = 4514;
person[8].name = "William", person[8].month = 11, person[8].day = 9, person[8].year = 1989, person[8].balance = 5412;
person[9].name = "Marjorie", person[9].month = 7, person[9].day = 26, person[9].year = 1985, person[9].balance = 6553;
person[10].name = "Neal", person[10].month = 5, person[10].day = 8, person[10].year = 1961, person[10].balance = 1917;
person[11].name = "Kathy", person[11].month = 10, person[11].day = 20, person[11].year = 1971, person[11].balance = 4396;
person[12].name = "Pattie", person[12].month = 12, person[12].day = 5, person[12].year = 2007, person[12].balance = 159,
person[13].name = "Darron", person[13].month = 8, person[13].day = 5, person[13].year = 1952, person[13].balance = 7694;
person[14].name = "Meri", person[14].month = 4, person[14].day = 16, person[14].year = 1976, person[14].balance = 2436;
person[15].name = "Mariann", person[15].month = 12, person[15].day = 7, person[15].year = 1966, person[15].balance = 3756;
person[16].name = "Manuela", person[16].month = 1, person[16].day = 17, person[16].year = 1978, person[16].balance = 4011;
person[17].name = "Angelita", person[17].month = 4, person[17].day = 30, person[17].year = 1944, person[17].balance = 1000;
person[18].name = "Nida", person[18].month = 1, person[18].day = 16, person[18].year = 1980, person[18].balance = 7411;
person[19].name = "Vanetta", person[19].month = 6, person[19].day = 3, person[19].year = 2013, person[19].balance = 7956;
person[20].name = "Gussie", person[20].month = 9, person[20].day = 21, person[20].year = 1997, person[20].balance = 7113;
person[21].name = "Jaymie", person[21].month = 10, person[21].day = 8, person[21].year = 1957, person[21].balance = 7936;
person[22].name = "Mitsuko", person[22].month = 9, person[22].day = 6, person[22].year = 1960, person[22].balance = 177;
person[23].name = "Shirly", person[23].month = 6, person[23].day = 12, person[23].year = 1946, person[23].balance = 1317;
person[24].name = "Luvenia", person[24].month = 6, person[24].day = 10, person[24].year = 1950, person[24].balance = 30,
person[25].name = "Minda", person[25].month = 7, person[25].day = 9, person[25].year = 1939, person[25].balance = 40;
person[26].name = "Carlo", person[26].month = 3, person[26].day = 3, person[26].year = 1965, person[26].balance = 50;
person[27].name = "Clotilde", person[27].month = 9, person[27].day = 25, person[27].year = 2013, person[27].balance = 1436;
person[28].name = "Luci", person[28].month = 12, person[28].day = 10, person[28].year = 1944 , person[28].balance = 6585;
person[29].name = "Agnus", person[29].month = 12, person[29].day = 16, person[29].year = 1937, person[29].balance = 1991;
person[30].name = "Magdalen", person[30].month = 10, person[30].day = 30, person[30].year = 2006, person[30].balance = 4050;
person[31].name = "Mariana", person[31].month = 5, person[31].day = 5, person[31].year = 2017, person[31].balance = 4514;
person[32].name = "Billie", person[32].month = 5, person[32].day = 30, person[32].year = 1961, person[32].balance = 5412;
person[33].name = "Walter", person[33].month = 7, person[33].day = 26, person[33].year = 1925, person[33].balance = 6553;
person[34].name = "Vincent", person[34].month = 7, person[34].day = 10, person[34].year = 1961, person[34].balance = 1917;
person[35].name = "Jeannette", person[35].month = 11, person[35].day = 20, person[35].year = 1933, person[35].balance = 4396;
person[36].name = "Noah", person[36].month = 12, person[36].day = 13, person[36].year = 1973, person[36].balance = 159,
person[37].name = "Julian", person[37].month = 5, person[37].day = 28, person[37].year = 2012, person[37].balance = 7694;
person[38].name = "Guadalupe", person[38].month = 9, person[38].day = 16, person[38].year = 1921, person[38].balance = 2436;
person[39].name = "Melanie", person[39].month = 9, person[39].day = 16, person[39].year = 1972, person[39].balance = 3756;
person[40].name = "Ramon", person[40].month = 8, person[40].day = 20, person[40].year = 2007, person[40].balance = 4011;
person[41].name = "Toby", person[41].month = 8, person[41].day = 25, person[41].year = 1993, person[41].balance = 1000;
person[42].name = "Stella", person[42].month = 1, person[42].day = 16, person[42].year = 1980, person[42].balance = 7411;
person[43].name = "Bruce", person[43].month = 5, person[43].day = 7, person[43].year = 1999, person[43].balance = 7956;
person[44].name = "Copper", person[44].month = 12, person[44].day = 8, person[44].year = 2004, person[44].balance = 7113;
person[45].name = "Barnett", person[45].month = 3, person[45].day = 21, person[45].year = 1958, person[45].balance = 7936;
person[46].name = "Warner", person[46].month = 7, person[46].day = 23, person[46].year = 1987, person[46].balance = 177;
person[47].name = "Dennis", person[47].month = 8, person[47].day = 30, person[47].year = 1984, person[47].balance = 1317;
person[48].name = "Sarah", person[48].month = 6, person[48].day = 17, person[48].year = 1986, person[48].balance = 4349;
person[49].name = "Jerry", person[49].month = 8, person[49].day = 4, person[49].year = 1968, person[49].balance = 6517;
person[50].name = "Anna", person[50].month = 7, person[50].day = 8, person[50].year = 1951, person[50].balance = 2420;
person[51].name = "Carl", person[51].month = 2, person[51].day = 25, person[51].year = 1950, person[51].balance = 2446,
person[52].name = "Anthony", person[52].month = 3, person[52].day = 14, person[52].year = 1990, person[52].balance = 1528;
person[53].name = "Bobby", person[53].month = 9, person[53].day = 14, person[53].year = 1951, person[53].balance = 3480;
person[54].name = "Clarence", person[54].month = 3, person[54].day = 4, person[54].year = 2014, person[54].balance = 860;
person[55].name = "Marilyn", person[55].month = 4, person[55].day = 15, person[55].year = 1998, person[55].balance = 7018;
person[56].name = "Paul", person[56].month = 5, person[56].day = 28, person[56].year = 1939, person[56].balance = 6939;
person[57].name = "Martin", person[57].month = 3, person[57].day = 14, person[57].year = 1920, person[57].balance = 4035;
person[58].name = "Jean", person[58].month = 2, person[58].day = 7, person[58].year = 1934, person[58].balance = 7435;
person[59].name = "Mary", person[59].month = 12, person[59].day = 25, person[59].year = 1952, person[59].balance = 4439;
person[60].name = "Teresa", person[60].month = 10, person[60].day = 1, person[60].year = 1959, person[60].balance = 7867;
person[61].name = "Andrea", person[61].month = 1, person[61].day = 11, person[61].year = 2005, person[61].balance = 2793;
person[62].name = "Edward", person[62].month = 4, person[62].day = 14, person[62].year = 1924, person[62].balance = 2355;

priority_queue<information, vector<information>, Comp> pq;
srand(time(NULL));
for (int i = 0; i < 10; i++)
{
RNG = rand() % (63 - 1) + 1;
pq.push(person[RNG]);
}

while (!pq.empty())
{
information r = pq.top();
pq.pop();
cout << "Name = "<<r.name << " Month = " << r.month << " Day = " << r.day << " Year = " << r.year << " Balance = " << r.balance << endl;
}
system("Pause");
return 0;
}

For every c++ code you must include some libraries :

for every program you must use : #include<iostream>

for every program using string you must use :#include<string>

for every program using priority queue you must use : #include<queue>

using namespace std is used so as to use 'cout' and 'cin' function directly without calling std.

Add a comment
Know the answer?
Add Answer to:
#include <iostream> #include <queue> #include <string> #include <vector> ...
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
  • Write a program that, given a month and year, prints a calendar, such as June 2016...

    Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr Sa 5 6 7 8 910 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 To find out the weekday of the first day of the month, call this function: Computes the weekday of a given date. @param year the year @param month the month (1=January 12=...

  • please determine the output in a simple form #include <stdio.h> 2 3 //Item 02 4 int...

    please determine the output in a simple form #include <stdio.h> 2 3 //Item 02 4 int main() 5 6 7 8 9 10 int i for( i = 0 ; i < 5 ; i++ ) ifo 12 13 14 15 16 17 18 19 20 21 printf("A" printf("B"); if i > 2 ) printf("C"); 23 24 25 26 27 28 29 30 31 32 if( i 3) printf( "D") if>4) printf("E 34 35 36 37 38 39 40 41...

  • Calculate the mean, median, and standard deviation for the total number of candies (per bag). Construct...

    Calculate the mean, median, and standard deviation for the total number of candies (per bag). Construct a histogram of the total number of candies (per bag). Use the z-score method to identify any potential outliers and outliers. Assume the total number of candies is normally distributed, calculate the probability that a randomly sampled bag has at least 55 candies in a bag. If a random sample of 50 bags is selected, find the probability that the mean number of candies...

  • Write a program in C that stores the result of all multiplications between 1 and 9...

    Write a program in C that stores the result of all multiplications between 1 and 9 in a two-dimensional int array and then prints the contents of the array to the screen. Also, write some comments in the code. Example: Expected output: 1 4 6 7 8 8 1 12 14 16 18 4 3 6 9 12 15 18 21 24 27 4 8 12 16 20 24 28 32 36 5 1e 15 20 25 30 35 40...

  • Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays...

    Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays for the wind speed and for the temperature. You will then use the stored data to calculate and output the average wind speed and the average temperature. Create a constant with a value of 30 and use that to declare and loop through your arrays and as a divisor to produce your averages. Here is the data file (below). 1. 14 25 2. 12...

  • Game   Point_Differential   Assists   Rebounds   Turnovers   Personal_Fouls 1   15   15   38   11   9 2   36   20   43 &

    Game   Point_Differential   Assists   Rebounds   Turnovers   Personal_Fouls 1   15   15   38   11   9 2   36   20   43   8   13 3   16   21   29   7   13 4   45   22   46   11   11 5   12   11   40   7   22 6   -10   10   31   13   26 7   11   19   45   11   7 8   12   16   32   16   14 9   3   16   27   18   15 10   19   9   34   17   17 11   40   16   41   9   17 12   44   12   29   9   22 13   16  ...

  • 2. After building a scientific way for demand forecasting, Mary hoped Jason can propose the optimal...

    2. After building a scientific way for demand forecasting, Mary hoped Jason can propose the optimal inventory/ordering policies for these 4 products for the first week of 2018. The sale price/unit for each product is listed below: Product A =$230 Product B=$50 Product C=$5 Product D=$3 Jason decided to use ABC rule to classify these 4 products. ‘A’ category product(s) will have the target service level 95%. ‘B’ product(s) will have the target service level 90% and ‘C’ products(s) will...

  • if you arent able to get it exactly like the template thats ok Adjusted Trial Balance...

    if you arent able to get it exactly like the template thats ok Adjusted Trial Balance For the Month Ended June 30, 2020 Credit Adjusted Trial Balance Debit $ 3,712 3,904 480 Account Titles Cash Accounts Receivable Supplies Accounts Payable Unearned Service Revenue Owner's Capital Owner's Drawings Service Revenue Salaries and Wages Expense Miscellaneous Expense Supplies Expense Salaries and Wages Payable $ 1,382 160 5,760 550 4,300 1,260 256 1,900 $12,062 460 $12,062 Instructions (a) Prepare closing entries at June...

  • Chapter 10 Excel Assignm AutoSave OFF Formulas Data Review View Page Layout Draw Home Insert A...

    Chapter 10 Excel Assignm AutoSave OFF Formulas Data Review View Page Layout Draw Home Insert A A General 10 Arial A $.% 9 0 BIU Paste fx 047 D E C B A Name: ACC 213 Lab #9 for Chapter 10-Installment Notes & Amortization Tables 3 Instructions: First, complete the amortization table in Part 1 using the information provided. 4 Once the table is completed, then record the two joumal entries in Part 2. 5 Information: 6 Your car loan...

  • Bag Blue Orange Green Yellow Red Brown Total Number of Candies 1 9 13 14 10...

    Bag Blue Orange Green Yellow Red Brown Total Number of Candies 1 9 13 14 10 7 7 60 2 13 10 6 9 9 8 55 3 13 12 4 10 9 6 54 4 16 13 8 6 6 8 57 5 10 10 12 5 15 4 56 6 9 18 3 6 12 12 60 7 11 13 6 15 8 6 59 8 12 18 5 9 6 5 55 9 12 10 8 15...

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
Active Questions
ADVERTISEMENT