Homework Help Question & Answers

#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
ReportAnswer #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 Homework Help Answer
Add Answer of:
#include <iostream> #include <queue> #include <string> #include <vector> ...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Need Online Homework Help?
Ask a Question
Get FREE EXPERT Answers
WITHIN MINUTES