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
Next > < Previous
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.

Know the 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.
Similar Homework Help Questions
  • C++ Calander Program .......I'm sooooo close, I need your help. Will Rate LIFESAVER!!

    x.øi5starts in the right location but Feb, Mar, Apr, and every othermonth starts in the same spot as January, I'm sooo close please help mefix this lastproblem......CODE#include <iostream>#include <iomanip>#include <cmath>using namespace std;//function prototypesintFirst_Day_Of_Month(int y, int m);intNumber_Days_Of_Month(int y, int m);bool IsLeapYear(int y);void Print_Version();void Print_Head(int y);void Print_Month(int y, int m);void Print_Month_Head(int m);void main (){int year;Print_Version();cin>> year;Print_Head(year);for(int i=1; i<=12; i++){Print_Month(year, i);}cout<<"nnnGoodbye!n";}//Some Functionsvoid Print_Version(){cout<<"Enter any Year After 1753 to output a very pretty calendar for that year!n";}void Print_Head(int y){cout<<"nn"<<setw(21)<<y<<endl;}void Print_Month(int year, int month){int firstday,...

  • I know I'm on the right path, but don't know where to continue from here. This is a C++ assignmen...

    I know I'm on the right path, but don't know where to continue from here. This is a C++ assignment Your job is to write that will display a calendar for any given month of a given year. The user will need to type the number of the month as an integer from 1 to 12 (1 is for January, etc.), and the year as a 4-digit integer. This assignment simply requires that your program make use of more than...

  • Void Statements

    Can anyone see where theproblem is? What am I doing wrong? I can't get this to compilecorrectly. Errors are showing up on the follow:( voidgetDate, VoiddayNumber, &void outputDay)#include <iostream>using namespacestd;bool isLeapYear (intyear);voidgetDate(month,day,year);void dayNumber(month,day,year,dayOfYear);void outputDay(month,day,year,dayOfYear);int main (){int day, month, year;int dayOfYear;cout << "This program prints the day number:" <<endl;getDate(month,day,year);dayNumber(month,day,year,dayOfYear);outputDay(month,day,year,dayOfYear);system("PAUSE");return0;}bool isLeapYear (int year){if (((year%4==0) &&(year%100!=0) )||((year%100==0 )&&(year %400==0 )))returntrue;return false;}void getDate(int&month ,int&day ,int&year){char ch;cout << "Please enter a date (mm-dd-yyyy): " ;cin >> month;cin>>ch;cin >> day ;cin>>ch;cin >> year;}void dayNumber(intmonth,int day,int year,int&dayOfYear){dayOfYear...

  • Calendar c programming

    write a program that prints out a calendar for a full year between 1900-2500January 1994Su Mo Tu We Th Fr Sa12 3 4 5 6 7 89 10 11 12 13 14 1516 17 18 19 20 21 2223 24 25 26 27 28 2930 31void greetings()printf("Cal assignment");int getYear()int yprintf(" enter between 1900 and 2500n");scanf("%d, &y);if(y>=1900 &&(y<=2500)return y;elseexit(1);int printCalendar1()this function is supposed to be for the leap yearint printCalendar2()(this function is supposed to be for the normal year

  • Use the Tornadoes Data and your statistical expertise to answer the questions: Is it reasonable to claim that the averag...

    Use the Tornadoes Data and your statistical expertise to answer the questions: Is it reasonable to claim that the average number of observed tornadoes per year is different from the average number of tornado related deaths per year? 5. What test/procedure did you perform? a. One-sided t-test b. Two-sided t-test c. Regression d. ​​Confidence interval 6. What is the P-Value/margin of error? a. 0.007034504 b. 0.34922 c. 4.07497E-24 d. 2.03749E-24 e. ​​None of these 7. Statistical Interpretation a. Since P-value...

  • projected sales

    Television Sales Time Series(in thousands)Day Sales Day Sales1 24 9 262 25 10 273 26 11 274 27 12 26.55 28.5 13 286 28 14 277 27 15 298 27.5What is the project sales for Day 16 using a three day moving average?What is the project sales for Day 16 using a six day moving average?Use the mean absolute deviation (MAD) and mean square error (MSE) to determine which average provides the better forecast

  • CALL EXCEL 3 4 5 6 HELP 7 8 9 10 11 12 26 13 27 OVERVIEW 14 15 28 29 17 16 30 18 19 20 21 22 23 24 25 Happy Lucky d...

    CALL EXCEL 3 4 5 6 HELP 7 8 9 10 11 12 26 13 27 OVERVIEW 14 15 28 29 17 16 30 18 19 20 21 22 23 24 25 Happy Lucky drove her car a total of 18,000 miles during 2019. Of this, 12,000 miles was related to business for JR Enterprises Happy paid $4,500 for gas, 55,500 for repairs, and $500 for tires during the year. Happy accounted to JR for these actual expenses and received...

  • write unix C code using for loop

    please write a unix C program using for loop to display following table.12 34 5 67 8 9 1011 12 13 14 1516 17 18 19 20 2122 23 24 25 26 27 2829 30 31 32 33 34 35 3637 38 39 40 41 42 43 44 4546 47 48 49 50 51 52 53 54 55

  • C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //...

    C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //class declaration 8 class stack Instructions Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same Overload the relational operatorfor the class stackType that returns true if two stacks of the same type are the same; it returns false...

  • A study of reading comprehension in children compared three methods of instruction. The three met...

    A study of reading comprehension in children compared three methods of instruction. The three methods of instruction are called Basal, DRTA, and Strategies. Basal is the traditional method of teaching, while DRTA and Strategies are two innovative methods based on similar theoretical considerations. The READING data set includes three response variables that the new methods were designed to improve. Analyze these variables using ANOVA methods. Be sure to include multiple comparisons or contrasts as needed. Write a report summarizing your...

Need Online Homework Help?
Ask a Question
Get FREE Expert Answers
WITHIN MINUTES