Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need help with this problem, I will give the best rating for who can help me/show me how to solve this question. p7.cxx

Hello, I need help with this problem, I will give the best rating for who can help me/show me how to solve this question.

image text in transcribedimage text in transcribed

p7.cxx

image text in transcribedimage text in transcribedimage text in transcribed

r1.cxx

image text in transcribed

r2.cxx

image text in transcribed

r3.cxx

image text in transcribed

Please help! I will give the best ratting :)

Task Recall some of the Week 03 Lecture Files, e.g., p7.cxx. r1.cxx. 12.cxx, and r3.cxx where: The p7 program was capable of reading in and writing out (playing) cards, i.e., struct card. r1 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): occurs time(s) where is the card and is the number of times it occurs in the histogram. (The output for card is the same as how p7.cxx's card type is output.) Tips Do look at p7, r1, 12, and r3 to write the code for this assignment. Copy the relevant bits you need in to your code. O NOTE: if you take p7.cxx and delete all lines starting at "struct cards" (i.e., line 85) to the end, then you will only need to write main() to do this assignment. :-) To output the histogram, use iterators to iterate through the map (or a range-for loop). O NOTE: Use prefix + + instead of postfix ++. Why? Prefix ++ and -- are more efficient --only use the postfix forms when they are absolutely needed. Each element in the map is a std::pair and one can access the Key via first or ->first and Value via.second or - > second Most of the code for this assignment is from the p7.cxx --but with the code handling cards removed and the code inside main() removed. Essentially this assignment is writing code in main() to compute a frequency histogram of cards since the rest of the code has been provided. Sample Program Input The program input will be a series of zero or more cards. (Read the input until EOF or an error.) For example, sample input might be placed in a file called input.dat, e.g. 1 2. $ cat input.dat 10D3S4H9C10D8H2D12S10D6H2D4H 3. Sample Program Run The program output for the above input.dat file is: 1. 2 3 4 $ g++-10.2.0 -Wall - Wextra Werror a3.cxx $ ./a.out 2 #include 3 #include 4 #include 5 using namespace std; 6 v struct card 7 { 8 enum class suit { club, spade, diamond, heart }; 9 enum { ace=1, jack=10, queen=11, king=12 }; 10 using number = int; 11 12 number num_; 13 suit suit_; 14 }; 15 16 bool operator =(card const& a, card const& b) 17 { 18 return a.num__ b.num_ && a.suit_ b.suit_; 19 } 20 21 v bool operator >(istream& is, card& c) 27 { 28 // number followed by the suit (CSHD)... 29 is >> c.num_; 30 31 char ch; 32 if (is >> ch) { 34 switch (ch) 35 { 23 33 34 35 36 37 38 39 40 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; 41 42 43 44 45 46 47 48 49 50 ostream& operator #include 2 3 4 using namespace std; 5 6 7 int main() { // map of (number, num of times number occurs)... map freqhist; 8 9 10 11 int i; while (cin >> i) #freqhist[i]; 23456 16 17 cout #include #include 4. 5 using namespace std; 6 7 v int main() 8 { 9 // map of (number, num of times number occurs)... 10 map freqhist; 11 12 string i; 13 while (cin >> i) 14 #freqhist[i]; 15 16 cout "FreqHist results: "; 17 for (auto const& elem : freqhist) 18 cout '(' elem.first ',' elem.second ") "; 19 } 1 v #include 2 #include 3 #include 4 5 using namespace std; 5 6 7 v int main() 8 { 9 // map of (number, num of times number occurs)... 10 map freqhist; 11 12 string i; 13 v while (cin >> i) 14 { 15 auto[pos, is_added] = freqhist.insert({i,1}); 16 if (!is_added) 17 Hpos+second; 18 } 19 20 cout occurs time(s) where is the card and is the number of times it occurs in the histogram. (The output for card is the same as how p7.cxx's card type is output.) Tips Do look at p7, r1, 12, and r3 to write the code for this assignment. Copy the relevant bits you need in to your code. O NOTE: if you take p7.cxx and delete all lines starting at "struct cards" (i.e., line 85) to the end, then you will only need to write main() to do this assignment. :-) To output the histogram, use iterators to iterate through the map (or a range-for loop). O NOTE: Use prefix + + instead of postfix ++. Why? Prefix ++ and -- are more efficient --only use the postfix forms when they are absolutely needed. Each element in the map is a std::pair and one can access the Key via first or ->first and Value via.second or - > second Most of the code for this assignment is from the p7.cxx --but with the code handling cards removed and the code inside main() removed. Essentially this assignment is writing code in main() to compute a frequency histogram of cards since the rest of the code has been provided. Sample Program Input The program input will be a series of zero or more cards. (Read the input until EOF or an error.) For example, sample input might be placed in a file called input.dat, e.g. 1 2. $ cat input.dat 10D3S4H9C10D8H2D12S10D6H2D4H 3. Sample Program Run The program output for the above input.dat file is: 1. 2 3 4 $ g++-10.2.0 -Wall - Wextra Werror a3.cxx $ ./a.out 2 #include 3 #include 4 #include 5 using namespace std; 6 v struct card 7 { 8 enum class suit { club, spade, diamond, heart }; 9 enum { ace=1, jack=10, queen=11, king=12 }; 10 using number = int; 11 12 number num_; 13 suit suit_; 14 }; 15 16 bool operator =(card const& a, card const& b) 17 { 18 return a.num__ b.num_ && a.suit_ b.suit_; 19 } 20 21 v bool operator >(istream& is, card& c) 27 { 28 // number followed by the suit (CSHD)... 29 is >> c.num_; 30 31 char ch; 32 if (is >> ch) { 34 switch (ch) 35 { 23 33 34 35 36 37 38 39 40 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; 41 42 43 44 45 46 47 48 49 50 ostream& operator #include 2 3 4 using namespace std; 5 6 7 int main() { // map of (number, num of times number occurs)... map freqhist; 8 9 10 11 int i; while (cin >> i) #freqhist[i]; 23456 16 17 cout #include #include 4. 5 using namespace std; 6 7 v int main() 8 { 9 // map of (number, num of times number occurs)... 10 map freqhist; 11 12 string i; 13 while (cin >> i) 14 #freqhist[i]; 15 16 cout "FreqHist results: "; 17 for (auto const& elem : freqhist) 18 cout '(' elem.first ',' elem.second ") "; 19 } 1 v #include 2 #include 3 #include 4 5 using namespace std; 5 6 7 v int main() 8 { 9 // map of (number, num of times number occurs)... 10 map freqhist; 11 12 string i; 13 v while (cin >> i) 14 { 15 auto[pos, is_added] = freqhist.insert({i,1}); 16 if (!is_added) 17 Hpos+second; 18 } 19 20 cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxxviii Special Issue On Database And Expert Systems Applications Lncs 11250

Authors: Abdelkader Hameurlain ,Roland Wagner ,Sven Hartmann ,Hui Ma

1st Edition

3662583836, 978-3662583838

More Books

Students also viewed these Databases questions

Question

Solve the given equations for x (0 x Answered: 1 week ago

Answered: 1 week ago

Question

4. List two examples of conceptual models and physical models

Answered: 1 week ago