cs161AWinter2024/table.cpp

69 lines
1.7 KiB
C++

#include <iostream>
#include <iomanip>
using namespace std;
void divider(){
cout << setfill('-');
cout << "|" << setw(20) << "";
cout << "|" << setw(10) << "";
cout << "|" << setw(10) << "";
cout << "|" << setw(5) << "";
cout << "|" << endl;
}
void printRow(string name, string color, double cost, double ml){
cout << setfill(' ');
cout << right;
cout << fixed << setprecision(2);
cout << "|" << setw(20) << name;
cout << "|" << setw(10) << color;
cout << "|" << setw(10) << cost;
cout << "|" << setw(5) << cost/ml;
cout << "|" << endl;
}
int main(){
//cout << "This is how things normally " << 10 << " look for us" << endl;
// now with setw
//cout << setw(30) << "This is how things normally" << setw(20) << 10 << setw(20) << "look for us" << endl;
// now we play with left vs. right justification
//cout << setfill('*');
//cout << left << setw(30) << "This is how things normally" << '|';
//cout << right << setw(20) << 10 << '|';
//cout << left << setw(20) << "look for us" << '|' << endl;
// starting our table
// make extra space
//cout << endl;
divider();
cout << setfill(' ');
cout << left;
cout << "|" << setw(20) << "Ink name";
cout << "|" << setw(10) << "Color";
cout << "|" << setw(10) << "Cost";
cout << "|" << setw(5) << "$/ml" << "|" << endl;
divider();
cout << setfill(' ');
cout << right;
cout << setprecision(2);
//cout << "|" << setw(20) << "Kon-Peki";
//cout << "|" << setw(10) << "Azure";
//cout << "|" << setw(10) << "$22.00";
//cout << "|" << setw(5) << 22.00/60;
//cout << "|" << endl;
printRow("Kon-Peki", "Azure", 22, 60);
divider();
cout << setprecision(1000);
printRow("Demeter", "Brown", 18, 90);
return 0;
}