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 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....

  • 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...

  • 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...

  • Needs some help [User-Defined Function] C++ Write a function, readWrite, that reads a set of test...

    Needs some help [User-Defined Function] C++ Write a function, readWrite, that reads a set of test scores stored in a file and calculates and returns the average of the numbers. The function returns a double and has the name of the file as its parameter. If the data is as follows, the average will be 5.66. 3 6 8

  • 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...

  • codeblock c++ language Write a program that reads students test scores in the range 0-200 from...

    codeblock c++ language Write a program that reads students test scores in the range 0-200 from a file until end of file (use e of() to check if ifstream reaches the End of File Stream) and store those scores in an array. It should then determine the number of students having scores in each of the following ranges: 0-24, 25-49, 50-74, 75-99, 100- 124, 125–149, 150-174, and 175–200. Finally, the program outputs the total number of students, each score range...

  • 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...

  • Write a program(Python language for the following three questions), with comments, to do the following:   ...

    Write a program(Python language for the following three questions), with comments, to do the following:    Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid Print “<str1> is a valid string.” If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message. If the first character of str1 is...

  • Use C++ language. Write a program that gives and takes advice on program writing. The program...

    Use C++ language. Write a program that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the...

  • C++ programming language Write a program that contains following function: A function that receives a string...

    C++ programming language Write a program that contains following function: A function that receives a string of character, the function return true if the string contains letter c or C, otherwise, return false.

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
ADVERTISEMENT