Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Please: Output: Source: / TODO: Add a #include for the iostream, cstdlib, and string header files using namespace std; // TODO: Write a

In C++ Please:

Output:

image text in transcribed

Source:

/ TODO: Add a #include for the iostream, cstdlib, and string header files

using namespace std;

// TODO: Write a function that prints out an error message; the function returns

// void and has no parameters

void ErrorMessage() {}

// TODO: Write a function named CardValue; the function returns an int and takes

// a const string& as a parameter

int CardValue(const string& string_value) {}

// TODO: Write a function named IntCardValueToString; the function returns a

// string and takes an int as a parameter

string IntCardValueToString(int value) {}

// TODO: Write a function named SecretCardValue; it returns an int and takes two

// ints as parameters

int SecretCardValue(int base_value, int steps) {}

// TODO: Write a function named SuitMultiplier; the function returns an int and

// takes a const string& as a parameter.

int SuitOffset(const string& suit) {}

string Suit(const string& card) {}

string Value(const string& card) {}

// TODO: Write a function named SecretSteps; the function returns an int and

// takes three const string& as parameters.

int SecretSteps(const string& card_one, const string& card_two,

const string& card_three) {}

int main(int argc, char const* argv[]) {

if (argc

ErrorMessage();

return 1;

}

string base_card = string(argv[1]);

string card_one = string(argv[2]);

string card_two = string(argv[3]);

string card_three = string(argv[4]);

return 0;

}

Requirements:

image text in transcribedimage text in transcribedimage text in transcribed

$ ./mind_reader This program may only be used by a qualified technician. $ ./mind_reader JC 6C KC 5D The card is 20. $ ./mind_reader 65 QD JC KC The card is 95. $ ./mind_reader 80 85 AH 75 The card is KD. Write a program that reads in 4 cards using the two letter abbreviation codes from the command line using argc and argv. Check to make sure you have the correct number of inputs on the command line before proceeding. (Your program must have a total of 5 arguments before it can perform the trick.) Each command line argument, must be converted to a std::string type variable. Use the at() method of the std::string class to access the value and suit of the inputted card. (Do not use the [] operators!) When using the at() method it will return a char type. Convert the char type to a string type. For example: string hello = "Hello World"; // The first letter is at position o string letter_H = string(1, hello.at()); // The second letter is at position 1 string letter_e = string(1, hello.at(1)); // The letter d // Get the size of the string, subtract 1 which will give the location of the last letter string last_letter = string(1, hello.at(hello.size() - 1)); When using at() you should wrap each usage with a try/catch just like the try/catch pattern learned from the previous lab to catch errors. string hello = "Hello World"; string letter_e; try { letter_e = string(1, hello.at(1)); }catch (const std::exception& e) { ErrorMessage(); // exit will end the program abruptly and return 1 to the operating system. exit(1); } Use the exit() function to exit from your program if an error occurs in a function. Remember to #include to take advantage of the exit() function. If you need to use std::stoi() to convert a string to an integer. Use the try/catch pattern learned from the previous lab to catch errors. Write a function which will convert a string which represents a card's value to an integer. Remember that a card can have the numerical value of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 yet the values are represented by strings "A", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K". Handle the exceptional cases "A", "J", "Q", and "K" by mapping those strings onto the integer values 1, 11, 12, and 13 and use stoi() for all the other cases. Always use try and catch with stoi() to catch errors. The functions prototype is int CardValue(const string& string_value); . Write a function which will convert an integer value to a card's string value. The function prototype is string IntCardValueToString(int value); . The input is an integer such as 1 and it returns a string 'A'. If the value doesn't need to be converted to a letter, use the to_string() function to convert from an integer to a string. Write a function which will calculate the secret card's value. The function prototype is int SecretCardValue(int base_value, int steps); . You may find that converting a cards value from a string to an integer is best done by writing many if and else-if statements. Write a function that will return what value to add to the base card given the three other cards inputted. The function prototype is int SecretSteps(const string& card_one, const string& card_two, const string& card_three); . If two or more cards have the same value, use the card's suit to determine the order. The function SecretSteps() has very complicated logic if we mix integer values with string suits. Instead, follow the advice given in the tip to imagine the cards ordered by value and then by suit. Write a function named Suitoffset() which maps a given card's suit to an offset. Clubs have a 1 offset Diamonds have a 2 offset Hearts have a 3 offset Spaders have a 4 offset For example, 6C, 6D, 6H, and 65 will have the values 6, 7, 8, 9 because 6C is 6 + 0, 6D is 6 + 1, 6H is 6 + 2, and 6S is 6 + 3. This way, comparing the three cards given to SecretSteps() is straightforward. The function prototype is int Suitoffset(const string& suit); . The function takes a suit as a parameter and returns the starting index of that suit. Write a function void ErrorMessage(); which prints out "This program may only be used by a qualified technician. " whenever an error is encountered. Exit with a return status of 1 when there is an error. $ ./mind_reader This program may only be used by a qualified technician. $ ./mind_reader JC 6C KC 5D The card is 20. $ ./mind_reader 65 QD JC KC The card is 95. $ ./mind_reader 80 85 AH 75 The card is KD. Write a program that reads in 4 cards using the two letter abbreviation codes from the command line using argc and argv. Check to make sure you have the correct number of inputs on the command line before proceeding. (Your program must have a total of 5 arguments before it can perform the trick.) Each command line argument, must be converted to a std::string type variable. Use the at() method of the std::string class to access the value and suit of the inputted card. (Do not use the [] operators!) When using the at() method it will return a char type. Convert the char type to a string type. For example: string hello = "Hello World"; // The first letter is at position o string letter_H = string(1, hello.at()); // The second letter is at position 1 string letter_e = string(1, hello.at(1)); // The letter d // Get the size of the string, subtract 1 which will give the location of the last letter string last_letter = string(1, hello.at(hello.size() - 1)); When using at() you should wrap each usage with a try/catch just like the try/catch pattern learned from the previous lab to catch errors. string hello = "Hello World"; string letter_e; try { letter_e = string(1, hello.at(1)); }catch (const std::exception& e) { ErrorMessage(); // exit will end the program abruptly and return 1 to the operating system. exit(1); } Use the exit() function to exit from your program if an error occurs in a function. Remember to #include to take advantage of the exit() function. If you need to use std::stoi() to convert a string to an integer. Use the try/catch pattern learned from the previous lab to catch errors. Write a function which will convert a string which represents a card's value to an integer. Remember that a card can have the numerical value of 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 yet the values are represented by strings "A", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K". Handle the exceptional cases "A", "J", "Q", and "K" by mapping those strings onto the integer values 1, 11, 12, and 13 and use stoi() for all the other cases. Always use try and catch with stoi() to catch errors. The functions prototype is int CardValue(const string& string_value); . Write a function which will convert an integer value to a card's string value. The function prototype is string IntCardValueToString(int value); . The input is an integer such as 1 and it returns a string 'A'. If the value doesn't need to be converted to a letter, use the to_string() function to convert from an integer to a string. Write a function which will calculate the secret card's value. The function prototype is int SecretCardValue(int base_value, int steps); . You may find that converting a cards value from a string to an integer is best done by writing many if and else-if statements. Write a function that will return what value to add to the base card given the three other cards inputted. The function prototype is int SecretSteps(const string& card_one, const string& card_two, const string& card_three); . If two or more cards have the same value, use the card's suit to determine the order. The function SecretSteps() has very complicated logic if we mix integer values with string suits. Instead, follow the advice given in the tip to imagine the cards ordered by value and then by suit. Write a function named Suitoffset() which maps a given card's suit to an offset. Clubs have a 1 offset Diamonds have a 2 offset Hearts have a 3 offset Spaders have a 4 offset For example, 6C, 6D, 6H, and 65 will have the values 6, 7, 8, 9 because 6C is 6 + 0, 6D is 6 + 1, 6H is 6 + 2, and 6S is 6 + 3. This way, comparing the three cards given to SecretSteps() is straightforward. The function prototype is int Suitoffset(const string& suit); . The function takes a suit as a parameter and returns the starting index of that suit. Write a function void ErrorMessage(); which prints out "This program may only be used by a qualified technician. " whenever an error is encountered. Exit with a return status of 1 when there is an error

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

Students also viewed these Databases questions

Question

a. What are S, F, and P? Pg45

Answered: 1 week ago