Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Please: Source Code: using namespace std; // TODO: Write a function that prints out an error message; the function returns void and has

In C++ Please:

image text in transcribedimage text in transcribedimage text in transcribed

Source Code:

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 SecretCardValue; it returns an int and takes two ints as parameters

int SecretCardValue(int base_value, int steps){

}

// 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 SuitMultiplier; the function returns an int and takes a const string& as a parameter.

int SuitMultiplier(const string& suit){

}

// 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;

}

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 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 1/ 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(); 1/ 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", ")", "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, write a function named SuitMultiplier() which maps a given card into a numerical range. For example, all the clubs will be the values 1 through 13, all the diamonds will be 14 through 26, all the hearts will be 27 through 39, and all the spades will be 40 through 52. This way, comparing the three cards given to SecretSteps() is straightforward. The function prototype is int SuitMultiplier(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. 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 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 1/ 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(); 1/ 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", ")", "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, write a function named SuitMultiplier() which maps a given card into a numerical range. For example, all the clubs will be the values 1 through 13, all the diamonds will be 14 through 26, all the hearts will be 27 through 39, and all the spades will be 40 through 52. This way, comparing the three cards given to SecretSteps() is straightforward. The function prototype is int SuitMultiplier(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

Recommended Textbook for

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions

Question

Discuss how sustainability affects decision making.

Answered: 1 week ago