Question

c++ language Write a program that contains the following functions, i. A function isVowel that takes...

c++ language

Write a program that contains the following functions,
i. A function isVowel that takes in a character and returns true if it is a vowel and false otherwise
ii. A function that request from the user to enter in a sequence of characters, and outputs the number of vowels entered. (Use Function in a) to assist you, a sentinel value can be used to specify the end of the user input
iii. A function that reads 3 test scores from 5 different students stored in a file and returns the highest average test score

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

#include <iostream>

#include<bits/stdc++.h>

using namespace std;

//A function isVowel that takes in a character and returns true if it is a vowel and false otherwise

bool isVowel(char x)

{

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

return true;

else

return false;

}

//A function that request from the user to enter in a sequence of characters, and outputs the number of vowels entered.

int countVowels()

{

char ch;

int count = 0;

while(1)

{

cout<<"Enter a character (Press n or N to quit): ";

cin>>ch;

if(ch=='n' || ch == 'N')

{

break;

}

else

{

if (isVowel(ch)) // Check for vowel

++count;

}

}

return count;

}

//A function that reads 3 test scores from 5 different students stored in a file and returns the highest average test score

void getStudentsList(string file[],int n)

{

// Variables to store average score of a student

// and maximum average score

int avgScore;

int maxAvgScore = INT_MIN;

// List to store names of students

// having maximum average score

vector<string> names;

// Traversing the file data

for (int i = 0; i < n; i += 4) {

// finding average score of a student

avgScore = (stoi(file[i + 1]) +

stoi(file[i + 2]) +

stoi(file[i + 3])) / 3;

if (avgScore > maxAvgScore) {

maxAvgScore = avgScore;

// Clear the list and add name of student

// having current maximum average score in the list

names.clear();

names.push_back(file[i]);

}

else if (avgScore == maxAvgScore)

names.push_back(file[i]);

}

// Printing the maximum average score and names

// of students having this maximum average score

// as per the order in the file.

for (int i = 0; i < names.size(); i++) {

cout <<names[i] + " ";

}

cout << maxAvgScore;

}

int main()

{

cout<<"\nResult of first function:\n ";

char c;

cout<<"Enter a character: ";

cin>>c;

if( isVowel(c)==true)

cout<<"Entered character is vowel.";

else

cout<<"Entered character is consonent.";

cout<<"\n\nResult of second function:\n ";

int count = countVowels();

cout<<"The number of vowels entered: "<<count;

cout<<"\n\nResult of third function:\n ";

string file[] = { "Shrikanth", "20", "30",

"10", "Ram", "100", "50", "10","Mohan", "40", "50", "100","Charlie", "200", "20", "10","Tom", "10", "50", "50" };

// Number of elements in string array

int n= sizeof(file)/sizeof(file[0]);

getStudentsList(file,n);

return 0;

}

Output:

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
c++ language Write a program that contains the following functions, i. A function isVowel that takes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this task you are asked to completely implement the following functions (ie. write both the...

    In this task you are asked to completely implement the following functions (ie. write both the function header and function body) 1) You have been tasked to write a Processing function called isleapYear, which receives an integer representing a year. The function should return true if the year is a leap year and false otherwise. (For your information, a year is leap year if it is divisible by 4 but not 100, or is divisible by 400) 2) You have...

  • In Java, write a program that prompts the user to input a sequence of characters and...

    In Java, write a program that prompts the user to input a sequence of characters and outputs the number of vowels. You will need to write a method to return a value called isAVowel which will return true if a given character is a vowel and returns false if the character is not a vowel. A second method, called isAConstant, should return true if a given character is a constant and return false if the character is not a constant....

  • Write a C++ program that will count the number of words and vowels in a sentence....

    Write a C++ program that will count the number of words and vowels in a sentence. Create a bool function called isVowel that accepts a character as a parameter and returns a true if it’s a vowel (aeiou) and false otherwise. Create an int function named countVowels that will accept a string variable as a parameter and will return the number of vowels in it. Call the isVowel function as part of this process. Write an int function named countWords...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • Write a C++ program that contains the following functions. Have at least 3 arrays created in...

    Write a C++ program that contains the following functions. Have at least 3 arrays created in the main to test your functions using appropriate function calls ReadIn (A Function that request the user to fill up 2 arrays of size 10) CompareFunc (A function that takes in 2 arrays and compares them, and outputs an appropriate message if they are the same or not) ReverseFunc ( A function that takes in 2 arrays, and copies the content of the the...

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT