(Solved Homework): 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:

Don't use plagiarized sources. Get Your Custom Essay on
(Solved Homework): Your Name and G Number>…
Get an essay WRITTEN FOR YOU, Plagiarism free, and by an EXPERT!
Order Essay

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:

Homework Ocean
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

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.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents