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

All programs should be in one solution and one project using the \"Menu_Template

ID: 3716400 • Letter: A

Question

All programs should be in one solution and one project using the "Menu_Template." Each menu item should call a function that will allow the user to enter value for the specified character string, call a function that does the specified processing (passing parameters to it) and returns the answer, and then the primary function should print out the answer. How can I incorporate my programs into the menu template. Thumbs up to anyone who can help :)

Here is menu template:

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include <ctype.h>

#include <string.h>

void program_one ();

void program_two ();

void program_three ();

void program_four();

void program_five();

int main()

{

int menu_option = 0;

while (menu_option != 9) {

printf("<program name one> = 1 "); //Change this to your first program name. Nothing else.

printf("<program name two> = 2 "); //Change this to your second program name. Nothing else.

printf("<program name three> = 3 "); //Change this to your third program name. Nothing else.

printf("<program name three> = 4 "); //Change this to your fourth program name. Nothing else.

printf("<program name three> = 5 "); //Change this to your fifth program name. Nothing else.

printf("Please enter number or 9 to end ");

scanf("%d",&menu_option);

getchar();

if (menu_option==1) program_one();

if (menu_option==2) program_two();

if (menu_option==3) program_three();

if (menu_option == 4) program_four();

if (menu_option == 5) program_five();

}

return(0);

getchar();

}

void program_one() {

/* Program One Goes Here*/

//

printf("Program One "); //Replace this line with your program.

//

getchar();}

void program_two() {

/* Program Two Goes Here */

//

printf("Program Two "); //Replace this line with your program.

//

getchar();}

void program_three() {

/* Program Three Goes Here */

//

printf("Program Three "); //Replace this line with your program.

//

getchar();}

void program_four() {

/* Program Three Goes Here */

//

printf("Program Four "); //Replace this line with your program.

//

getchar();

}

void program_five() {

/* Program Three Goes Here */

//

printf("Program Five "); //Replace this line with your program.

//

getchar();

}

Here is program one:

#include <stdio.h>

#include <string.h>c

void revchars(char *x, char *y) {

char t = *x;

*x = *y;

*y = t;

}

void reverse(char *str) {

int len = strlen(str);

int i = 0, j = len - 1;

while (i < j) {

revchars(&str[i], &str[j]);

i++;

j--;

}

}

int main() {

char str[100];

printf("Enter string: ");

fgets(str, 100, stdin);

reverse(str);

printf("Reverse: %s ", str);

getchar();

return 0;

}

program two:

#include<stdio.h>

int countlets(char str[])

{

int i;

int count = 0;

for (i = 0; i<str[i] != ''; i++)

{

if (isalpha(str[i]))

count++;

}

return count;

}

int letter_counter()

{

char buff[1024];

int count;

printf("Enter the string: ");

gets(buff);

count = countlets(buff);

}

int main()

{

int count = letter_counter();

printf("The number of letters : %d", count);

getchar();

return 0;

getchar();

}

Program three:

#include<stdio.h>

void reverse_names(char f[], char l[]) {

printf("%s, %s ", l, f);

}

void names(char f[], char l[]) {

reverse_names(f, l);

}

int main()

{

char first[40];

char last[40];

printf("Enter first name: ");

gets(first); //first name

printf("Enter last name: ");

gets(last); //a last name

names(first, last);

getchar();

}

program four:

#include<stdio.h>

void sentences();

void sentence_counter(char ar[]);

main()

{

sentences();

}

void sentences()

{

char array[500];

printf("Enter setences:");

gets(array);

sentence_counter(array);

}

void sentence_counter(char array[500])

{

int i = 0, counter = 0;

for (i = 0; array[i] != ''; i++)

{

if (array[i] == '.' || array[i] == '?' || array[i] == '!')

{

counter++;

}

}

//display

printf("Number of sentences: %d ", counter);

getchar();

}

Explanation / Answer

Hi, your program for menu template: looks correct to me.
I have gone through the functinality been made in each program.

program 1: reversing the inputted string string.
program 2: counting the number of alpha in an inputted string.
program 3: swap the first and last names and print.
program 4: count the number of sentences in a given paragraph.

In all the programs except program 3 you have taken one character buffer or string of length 500/1000.
So better you take two char buffer of size 500 and 40(for 3rd program).

And then you write one program as program 5 to just print the buffer 1.

And now you need not to have main functions. And write the relevant theory in printf of Menu Section.

And the imp thing, in C/C++ the function definition always must be either declared or defined in file before calling it.
So you arranged all the function above the line where it been called.

void revchars(char *x, char *y) {

char t = *x;

*x = *y;

*y = t;

}

void reverse(char *str) {

int len = strlen(str);

int i = 0, j = len - 1;

while (i < j) {

revchars(&str[i], &str[j]);

i++;

j--;

}

}

/*END OF PROGRAM 1*/

int countlets(char str[])

{

int i;

int count = 0;

for (i = 0; i<str[i] != ''; i++)

{

if (isalpha(str[i]))

count++;

}

return count;

}

int letter_counter()

{

char buff[1024];

int count;

printf("Enter the string: ");

gets(buff);

count = countlets(buff);

}

/* END OF PROGRAM 2 -- you directly call above function. */

void reverse_names(char f[], char l[]) {

printf("%s, %s ", l, f);

}

void names(char f[], char l[]) {

reverse_names(f, l);

}

int change_name(char *first, char *last) /* I HAVE CHANGED THE MAIN TO change)name NAME - CALL FROM MENU.*/

{

printf("Enter first name: ");

gets(first); //first name

printf("Enter last name: ");

gets(last); //a last name

names(first, last);

getchar();

}

/* END OF PROGRAM 3 */

void sentence_counter(char array[500])

{

int i = 0, counter = 0;

for (i = 0; array[i] != ''; i++)

{

if (array[i] == '.' || array[i] == '?' || array[i] == '!')

{

counter++;

}

}

//display

printf("Number of sentences: %d ", counter);

getchar();

}

void sentences(char *array)

{

printf("Enter setences:");

gets(array);

sentence_counter(array);

}

/* DIRECTLY CALL sentences by passing buffer */

I hope you will be able to made the code now.

Thanks.