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
|
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
struct PrintJobs {
std::string m_customer ;
std::string m_jobName ;
int m_front = 0;
int m_back = 0;
int m_day = 1;
int m_quanity = 0;
char m_type = 'X' ;
};
std::ostream& operator <<( std::ostream& os, const PrintJobs& pJ ) {
return os << std::setw(20) << pJ.m_customer
<< std::setw(25) << pJ.m_jobName
<< std::setw(8) << pJ.m_quanity
<< std::setw(8) << pJ.m_front
<< std::setw(8) << pJ.m_back
<< std::setw(6) << pJ.m_type
<< std::setw(8) << pJ.m_day ;
}
std::ostream& print_header( std::ostream& os ) {
return os << std::setw(20) << "customer"
<< std::setw(25) << "job name"
<< std::setw(8) << "quanity"
<< std::setw(8) << "front"
<< std::setw(8) << "back"
<< std::setw(6) << "type"
<< std::setw(8) << "day"
<< '\n' << std::string( 90, '-' ) << '\n' ;
}
int main() {
std::vector<PrintJobs> jobs { { "customer one", "job one", 1, 2, 3, 4, 'A' },
{ "customer two", "job two", 5, 6, 7, 8, 'B' },
{ "customer three", "job three", 9, 10, 11, 12, 'A' },
{ "customer one", "job four", 13, 14, 15, 16, 'C' },
{ "customer two", "job five", 17, 18, 19, 20, 'B' }
} ;
int total_quanity = 0 ;
std::cout << " " ;
print_header(std::cout) ;
int slno = 0 ;
for( const auto& j : jobs ) {
std::cout << std::setw(3) << ++slno << ". " << j << '\n' ;
total_quanity += j.m_quanity ;
}
std::cout << "\ntotal number of jobs:" << std::setw(5) << jobs.size()
<< "\n total quanity:" << std::setw(5) << total_quanity << '\n' ;
}
|