1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include<string>
#include<vector>
#include<iostream>
#include <iomanip>
using namespace std;
struct date {
int d,m,y;
};
struct people{
string lastname;
string firstname;
string job;
int salary;
date dob;
};
void show(people p)
{
cout<<left<<setw(9)<<p.firstname<<setw(13)<<p.lastname<<setw(15)<<p.job<<setw(5)<<"DateOfBirth= "<<p.dob.d<<"."<<p.dob.m<<"."<<p.dob.y<<" Salary = "
<<p.salary<<endl;
}
int difference(date dt1, date dt2)
{
const int monthDays[12]
= { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
long int n1 = dt1.y * 365 + dt1.d;
for (int i = 0; i < dt1.m - 1; i++)
n1 += monthDays[i];
long int n2 = dt2.y * 365 + dt2.d;
for (int i = 0; i < dt2.m - 1; i++)
n2 += monthDays[i];
return (n2 - n1);
}
int range(int f ,int l)
{
return (rand() % ((l-f)+1)) + f;
}
int main()
{
srand(5000);
vector<string> ln={"Smith","Jones","Kelly","Macnab","Peterson","Anderson","Trump","Putin","Thatcher","Davies","Wilson","Flemming","Richardson"};
vector<string> fn={"Robert","Sally","James","Ann","Peter","Mary","Paul","Andrew","Charles","June","Wilma","Henry","Louis"};
vector<string> job={"clerk","assistant","engineer","sales person","trimmer","painter","trouble shooter"};
vector<people>p(13);
for(int i=0;i<p.size();i++)
{
p[i].lastname=ln[range(0,p.size()-1)];
p[i].firstname=fn[range(0,p.size()-1)];
p[i].job=job[range(0,6)];
p[i].salary=range(1000,2000);
p[i].dob={range(1,25),range(1,12),range(1970,2000)};
show(p[i]);
}
cout<<endl;
cout<<"less than 30 years old and earning more than 1500"<<endl<<endl;
date present={1,1,2021};
for(int i=0;i<p.size();i++)
{
if (p[i].salary>1500 && difference(p[i].dob,present)/365 < 30) show(p[i]);
}
system("pause");
}
|