Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a simple program called patterns . You\'ll present the user with a choice

ID: 3822573 • Letter: W

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, 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.

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.

Make use of the function std::to_string for converting numeric values to strings

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:

Sample Menu

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

GIve me one of the part of this program or whole one

Explanation / Answer

#include <iostream>
using namespace std;
bool checkPrime(int);
bool checkPrime(int num){
int i;
bool isPrime =true;
for(i = 2; i <= num / 2; ++i)
{
if(num % i == 0)
{
isPrime= false;
break;
}
}
return isPrime;
}
int main()
{
int num;
cout << "Input a postive integer: ";
cin >> num;
if(num<=0){
cout<<" Error: Input a postive integer: !! ";
}else if(num==1){
cout<<" Not prime, but worth talking to a Professor of Maths about. ";
}else{
if(checkPrime(num))
cout<<num <<" is prime ";
else
cout<<num<< " is not a prime ";
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote