Answered Essay: Your Name and G Number>

<Your Name and G Number>
// CS 262, Lab Section <Lab Section Number>
// Lab 3

Your code must contain at least one of all of the following control types:

a for() loop

a while() or a do-while() loop

a switch() statement

an if-else statement

functions

Consider which control structures will work best for which aspect of the assignment.

The first thing your program will do is print a menu of choices for the user. (Hint: Which control type given above will work best for a menu?) You may choose your own version of the wording or order of choices presented, but each choice given in the menu must match the following:

Menu Choice Valid User Input Choices
Enter/Change Character ‘C’ or ‘c’
Enter/Change Number ‘N’ or ‘n’
Print Triangle Type 1 (Left Justified) ‘1’
Print Triangle Type 2 (Right Justified) ‘2’
Quit Program ‘Q’ or ‘q’

A prompt is presented to the user to enter a choice from the menu. If the user enters a choice that is not a valid input, a message stating the choice is invalid is displayed and the menu is displayed again.

Your executable file will be named Lab3_<username>_<labsection>
Your program must have at least four functions (not including main()) including:

A function that prompts the user to enter a single character. The return value of the function be a char and will return the character value entered by the user. This return value will be stored in a local variable, C, in main(). The initial default value of this character will be ‘ ‘ (blank or space character).

A function that prompts the user to enter a numerical value between 1 and 15 (inclusive). If the user enters a value outside this range, the user is prompted to re-enter a value until a proper value is entered. The return value of the function be an int and will return the value entered by the user. This return value will be stored in a local variable, N, in main(). The initial default value of this character will be 0.

Two “Print Triangle” functions. Each function will take the previously entered integer value N and character value C as input parameters (You will need to ensure that these values are valid before entering these functions). The return values of these functions will be void. The functions will print triangles of N lines containing the input character C. The Left Justified function will print the triangle with the characters Left-Justified. The Right Justified function will print the triangles with the characters “Right-Justified.” For example, if the integer value N = 6, and the character value C = ‘*’ and the Right Justified Triangle type is called, the following triangle will be printed:

*
**
***
****
*****
******

If the Left-Justified triangle is to be printed, then the following triangle is printed:

*
**
***
****
*****
******

Suggested Steps to Complete the Assignment:

You are not required to complete the following steps to write your program or even pay attention to them. However, if you do decide to use the suggested steps, you should test your program thoroughly to ensure each step works correctly before moving on to the next step.

Expert Answer

 

#include <stdio.h>

#include <stdlib.h>

//read the character

char readChar()

{

char C;

printf(“Enter the character:”);

scanf(” %c”,&C);

return C;

}

//read the integer

int readNumber()

{

int N;

do

{

printf(“Enter the number:”);

scanf(“%d”,&N);

if(N<=15&&N>=1)

break;

}

while(1);

return N;

}

//print the triangle as right justified

void printRightJust(char C,int N)

{

int i,j,k;

for(i=1; i<=N; i++)

{

for(j=N-1; j>=i; j–)

{

printf(” “);

}

for(k=1; k<=(2*i-1); k++)

{

printf(“%c”,C);

}

printf(“n”);

}

}

//print the triangle as left justified

void printLeftJust(char C,int N)

{

int i,j;

for(i=1; i<=N; ++i)

{

for(j=1; j<=i; ++j)

{

printf(“%c “,C);

}

printf(“n”);

}

}

int main()

{

char C=’ ‘;

int N=0;

int ch;

do

{

printf(“1. Enter/Change Character ‘C’ or ‘c’n”);

printf(“2. Enter/Change Number ‘N’ or ‘n’n”);

printf(“3. Print Triangle Type 1 (Left Justified) ‘1’n”);

printf(“4. Print Triangle Type 2 (Right Justified) ‘2’n”);

printf(“5. Quit Program ‘Q’ or ‘q’n”);

printf(“Enter the choice:”);

scanf(“%d”,&ch);

if(ch==5)break;

switch(ch)

{

case 1:

C=readChar();

break;

case 2:

N=readNumber();

break;

case 3:

printLeftJust(C,N);

break;

case 4:

printRightJust(C,N);

break;

case 5:

break;

default:

printf(“Invalid choicen”);

break;

}

}

while(1);

return 0;

}

OUTPUT:

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.