Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Practice Questions: 1. Write a program that takes user input describing a playing card in the following shorthand notation: Shorthand Name A Ace 210

C++ Practice Questions:

1. Write a program that takes user input describing a playing card in the following shorthand notation:

Shorthand Name
A Ace
210 Card values
J Jack
Q Queen
K King
D Diamonds
H Hearts
S Spades
C

Clubs

Your program should print the full description of the card.

For example, with input QS given: Enter the card notation: QS Queen of Spades

For example, with input 9H given: Enter the card notation: 9H 9 of Hearts

2. Write a function called isValidMinute that is passed a minute as an integer and returns a Boolean true if the value is 0 to 59 and a Boolean false if it is not. Include documentation for the function.

3. Write a program which displays a set of 2 randomly picked initials (i.e. SM or MJ) and then asks the user if they are theirs. If the user answers yes, display the message What a lucky guess! If the user answers no, display the message That is 1 wrong guess! and then repeats guessing with new random initials until it is correct. Do not document your code.

4. Create a loop that outputs every other powers of two (starting with 2^0) until you have outputted 10 values. You may utilize the pow function implemented in cmath.

5. Create a function definition that converts an array of characters into a string. The function should not change the original array. The function will take the character array and the number of characters as input. The function returns a string containing the characters in the array. See the example below.

double doubletoint(double arrayin[], const int& SIZE) //The fractional part of each element in the passed array (on left) //is made 0 (shown on the right) and the removed fractional part of //each is added together and and returned. 

6. What is the value of k[1] and k[3] if 2, 0, 1 are entered for each cin (in that order)?

int k[6] = {0, 0, 0, 0, 0, 0} Data: 2 0 1 int i, n; for (i = 3; i < 6; i++) { cin >> n; k[n] = i; }

7. Create a function that copies the values in one array to another

void copyDoubleA ( const double a[],// IN: array to be copied (contents of this array do NOT change) double b[], // OUT: same as array a upon exit int size); // IN: number of elements in array a and b );

8. What does the following function do?

int fun(string a) { int k=a.length()-1; char blank = ' '; bool looking = true; while (k >= 0 && looking) if (a[k] == blank) --k; else looking = false; if (looking) return -1; else return k; }

a) Finds and returns the subscript of the first nonblank character in string a.

b) Finds and returns the subscript of the last nonblank character in string a.

c) Counts and returns the number of nonblank characters in string a.

d) Finds and returns the subscript of the first blank in string a.

e) Finds and returns the subscript of the last blank in string a.

9. Write a function that reads in integers. When the sum is greater than or equal to 100, your function should return the number of integers the user entered in.

Sample session:

Enter integer 50 Enter integer 40 Enter integer 9 Enter integer 5 Sum is now greater than or equal to 100

10. Write a function that is passed two int arrays along with their sizes. Your function should return true if the two lists have identical contents, and false otherwise.

bool equalArrays(int arrA[], int sizeA, int arrB[], int sizeB)

11. Write a function that tosses a coin 1000 times. Your program should determine the longest run of heads and return the longest run. Represent heads with 1; tails with 0.

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

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions