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

I need the programs to be in C code, if possible can you provide a screen shot o

ID: 3842750 • Letter: I

Question

I need the programs to be in C code, if possible can you provide a screen shot of the solution running please.

Lab 9.1 Write a program that prompts for your first name and then last name. Enter them respectively and make your full name and output it.

Lab 9.2

Write a program that finds the smallest word and largest word in a series of words. The program must stop accepting input when the user enters “stop”. Assume that no word is more than 20 letters long. The following is an example run:

Enter word: dog

Enter word: zebra

Enter word: rabbit

Enter word: cat

Enter word: fish

Enter word: stop

Smallest word: cat

Largest word: zebra

Lab 9.3. In Lab 4.2 you were asked to write a program that counts the number of vowels (a,e,i,o,u) in a sentence entered from the keyboard. Now define a function that contains a string parameter. The function will counts the number of vowels in the string parameter and returns the count. Call the function in the main.

4.2 Lab code:

char sentence;

       int vowels = 0;

       int i;

       printf("Enter a Sentence: ");

       sentence = getchar();

       while (sentence != ' ')

       {

              if (sentence == 'a' || sentence == 'e' || sentence == 'i' || sentence == 'o' || sentence == 'u' || sentence == 'A' || sentence == 'E' || sentence == 'I' || sentence == 'O' || sentence == 'U')

              {

                     vowels++;

              }

              sentence = getchar();

       }

       printf("There are %d vowels in the given sentence ", vowels);

Lab 9.1 Write a program that prompts for your first name and then last name. Enter them respectively and make your full name and output it.

Lab 9.2

Write a program that finds the smallest word and largest word in a series of words. The program must stop accepting input when the user enters “stop”. Assume that no word is more than 20 letters long. The following is an example run:

Enter word: dog

Enter word: zebra

Enter word: rabbit

Enter word: cat

Enter word: fish

Enter word: stop

Smallest word: cat

Largest word: zebra

Lab 9.3. In Lab 4.2 you were asked to write a program that counts the number of vowels (a,e,i,o,u) in a sentence entered from the keyboard. Now define a function that contains a string parameter. The function will counts the number of vowels in the string parameter and returns the count. Call the function in the main.

Explanation / Answer

Lab 9.1

#include <stdio.h>

#define NAME_LENGTH 20

int main (void)
{
   char first_initial, last_name[NAME_LENGTH];
   int i = 0;
   
   printf(" Enter a first and last name: ");
   scanf(" %c", &first_initial); // gets first letter of first name. Ignores leading blank spaces//
   printf("You entered the name: ");
  
   while (getchar() != ' '){
       // ignore remaining first name characters until a blank space is reached //
        ;
   }
  
   while ((last_name[i] = getchar()) != ' '){
       if (last_name[i] == ' ')
       /* ignore blank spaces before and after last name */
       ;
       else
           printf("%c", last_name[i++]);
   }

   printf(", %c. ", first_initial);

   return 0;
}

Lab 9.2

#include <stdio.h>
#include <string.h>

#define WORD_LEN 20

void read_line (char str[], int n);

int main (void)
{
   char smallest_word[WORD_LEN+1];
   char largest_word[WORD_LEN+1];
   char current_word[WORD_LEN+1];
  
   printf("Enter word: ");
   read_line (current_word, WORD_LEN);
   strcpy(smallest_word, strcpy(largest_word, current_word));
  
   while (strlen(current_word) != 4){
       printf("Enter word: ");
       read_line(current_word, WORD_LEN);
       if (strcmp(current_word, smallest_word) < 0)
           strcpy(smallest_word, current_word);
       if (strcmp(current_word, largest_word) > 0)
           strcpy(largest_word, current_word);
   }
  
   printf(" Smallest word: %s ", smallest_word);
   printf("Largest word: %s ", largest_word);
  
   return 0;
}

void read_line (char str[], int n)
{
   int ch, i = 0;
  
   while ((ch = getchar()) != ' ')
       if (i < n)
           str[i++] = ch;
   str[i] = '';
}

Lab 9.3

#include <stdio.h>
#include <ctype.h>

#define STR_LEN 61

int compute_vowel_count (const char *sentence);
int read_line (char str[], int n);

int main (void)
{  
   char sentence[STR_LEN];
  
   printf(" Enter a sentence: ");
   read_line (sentence, STR_LEN);
  
   printf("Your sentence contains %d vowels. ", compute_vowel_count(sentence));
  
   return 0;
}

int read_line (char str[], int n)
{
   int ch, i;
  
   for (i = 0; i < n; i++) {
       ch = getchar();
       if (ch == ' ')
           break;
       str[i] = ch;
   }
   str[i] = '';
  
   return i;
}
  
int compute_vowel_count (const char *sentence)
{
   int count = 0;
   char ch;

   while (*sentence){
        ch = *sentence++;
          
        switch (toupper(ch)) {
            case 'A': case 'E': case 'I': case 'O': case 'U':
                count++ ;
        }
   }
  
   return count;
}

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