Question
P7: #include #include #include #include #include using namespace std; //------ struct card { enum class suit { club, spade, diamond, heart }; enum { ace=1,
P7:
#include
using namespace std;
//------
struct card { enum class suit { club, spade, diamond, heart }; enum { ace=1, jack=10, queen=11, king=12 }; using number = int;
number num_; suit suit_; };
bool operator ==(card const& a, card const& b) { return a.num_ == b.num_ && a.suit_ == b.suit_; }
bool operator
istream& operator >>(istream& is, card& c) { // number followed by the suit (CSHD)... is >> c.num_;
char ch; if (is >> ch) { switch (ch) { case 'C': c.suit_ = card::suit::club; break; case 'S': c.suit_ = card::suit::spade; break; case 'H': c.suit_ = card::suit::heart; break; case 'D': c.suit_ = card::suit::diamond; break; default: is.setstate(ios::failbit); break; } } else is.setstate(ios::badbit); return is; }
ostream& operator
switch (c.suit_) { // card::suit allows us to access suit // suit::club allows us to access club // thus, card::suit::club lets us access club case card::suit::club: os
case card::suit::spade: os
case card::suit::diamond: os
case card::suit::heart: os
return os; }
//------
int main(){
}
R1:
#include
using namespace std;
int main() { // map of (number, num of times number occurs)... map
int i; while (cin >> i) ++freqhist[i];
cout
R2:
#include
using namespace std;
int main() { // map of (number, num of times number occurs)... map
string i; while (cin >> i) ++freqhist[i];
cout
R3:
#include
using namespace std;
int main() { // map of (number, num of times number occurs)... map
string i; while (cin >> i) { auto[pos,is_added] = freqhist.insert({i,1}); if (!is_added) ++pos->second; }
cout
**YOU ONLY HAVE TO CODE THE INT MAIN() IN P7 TO COMPLETE THIS**
The objective of this assignment is to read in a list of (playing) cards from standard input and output a frequency histogram of the playing cards read in. Task Recall some of the Week 03 Lecture Files, e.g.p7.cxx, r1.cxx, r2.cxx, and r3.cxx where: The p7 program was capable of reading in and writing out (playing) cards, i.e., struct card. 1 to r3 was capable constructing a frequency histogram. This assignment's task is to read in card structs from standard input and place such in to a frequency histogram. Input is to occur until EOF (end-of-file) or an input error occurs. After reading in all input, for each entry in the frequency histogram's map output the following (always on its own line): .Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started