Question: Write a simple program called patterns . You'll present the user with a choice of patterns (e.g. Checker Board). Once the user chooses a pattern,
Write a simple program called patterns. You'll present the user with a choice of patterns (e.g. Checker Board). Once the user chooses a pattern, the user then sets the size of the pattern. The size will be an integer larger than 1. Finally, the user chooses to print the pattern to the screen or to save it to a file of their choosing.
If the user gives an invalid size or menu choice, display the text "Error." and exit. ask the user for valid input a again.
Even after valid input, the entire program should repeat until the user wants to quit (you can do a simple (y/n) prompt)
Patterns
Here are sample patterns where n=5.
Checkerboard
Normal checkerboard patter of uppercase O's and X's.
OXOXO XOXOX OXOXO XOXOX OXOXO
Twin Islands
There are two islands, one made of '!' in the top left and one made of '?' in the bottom right. There is a border in the middle and ocean everywhere else.
!!~~* !!~*~ ~~*~~ ~*~?? *~~??
Running total
You print an NxN matrix of numbers seperated by commas.
The pattern is simply a running total of values where each row contains only N values.
1,2,3,4,5 6,7,8,9,10 11,12,13,14,15 16,17,18,19,20 21,22,23,24,25
Make use of the function std::to_string for converting numeric values to strings
std::string myStr; myStr = std::to_string( 42 );//converts 42 to the string "42"
Upper Left Triangle
Print a trianble of '*' in the upper left portion.
***** **** *** ** *
Upper Right Triangle
Print a triangle of '*' in the upper right portion..
***** **** *** ** *
Required Functions
For each of the patterns, you will create a function dedicated to create a string to hold the pattern. Each function will take the dimension, N, as a parameter and return a string.
THE FUNCTIONS DO NOT PRINT ANYTHING
Example:
std::string checkerBoard(int n) { std::string pattern = ""; //code to load the pattern into the string return( pattern ); } Sample Menu
1) Checkerboard 2) Twin Islands 3) Running Total 4) Upper Left Triangle 5) Upper Right Triangle Choice: 1 (F)ile or (P)rint: f Enter a file name to save pattern to: myBoard.txt Pattern saved to myBoard.txt Would you like to quit (y/n): y Goodbye.
Notes:
Verify all input from user with the failbit technique shown above.
Prompt the user until good input is supplied
'F' or 'f' indicates file
'P' or 'p' indicates print to terminal
'Y' or 'y' allows user to exit at the end prompt
Exercise 3 (169 only): Prime Program
Prime or not a prime? Create a program Prime that will obtain a positive integer from the user. You will then tell the user if the number is a prime number or is not a prime number.
What is a prime number? A prime number is a number that is only divisible by itself and 1 (no remainder). Here are the first few primes: 2, 3, 5, 7, 11, 13. You can find huge lists online of prime numbers, but we will write a program that will calculate whether or not a number is prime.
Special cases:
Negative number - display error message
0 - display error message
1 - Display "Not prime, but worth talking to a Professor of Maths about."
2 or above - determine if the number is a prime
Notes:
We should be able to test with any valid positive integer
Depending on your implementation, some runs will take a long time to complete
We're not looking for one "best" solution, and you don't have to research any complicated mathematical formulas. There will be many solutions to this problem. The purpose is to let you explore and do some critical thinking.
You won't be graded on efficiency, but your program should find a solution in a reasonable amount of time
Sample Output
Input a positive integer: 3 3 is prime
Input a positive integer: 40 40 is not prime
Input a positive integer: 0 Error: Input a positive integer
Input a positive integer: 1 Not prime, but worth talking to a Professor of Maths about.
Input a positive integer: 7919 7919 is prime
GIve me one of the part of this program or whole one
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
