in c++ Finish the methods in the following code. DO
NOT CHANGE THE MAIN METHOD. The instructions for each method are in
a comment in the template. DO NOT CHANGE THE MAIN
METHOD!!!!
#include <iostream> #include <string>
using namespace std; // prototypes int main() { int answer = 0; int
value1 = 0; int value2 = 0; double average = 0; string string1 =
""; int numberVowels = 0; int numberNonVowels = 0; cout <<
"Enter string1: "; getline(cin, string1); cout << "Enter
value1: "; cin >> value1; cout << "Enter value2: "; cin
>> value2; cout << endl; cout.setf(ios::fixed);
cout.precision(2); answer = summationBetween(value1, value2); cout
<< "The summation is: " << answer << endl
<< endl; numberVowels =
countVowelsAndOtherCharacters(string1, numberNonVowels); cout
<< "The string \"" << string1 << "\" has "
<< numberVowels << " vowels and "; cout <<
numberNonVowels << " characters that are not vowels. "; cout
<< endl; cout << endl; average = calculateAverage();
cout << endl; cout << "The average is: " <<
average << endl; return 0; } // Function: summationBetween //
This function adds all the numbers between two numbers. It takes in
two integers. // It adds the starting number and the ending number
into the sum as well. // The total is returned. // Function:
countVowelsAndOtherCharacters // This function counts the number of
vowels and the number of nonvowels. It takes in a // string and an
integer. It returns the number of vowels. // Function:
calculateAverage // This function queries the user for values. It
takes in no arguments. // It returns the average of the
numbers.
Sample output using VSCode. Part of the output comes
from the main method.
Enter string1: Helloooo Nurse! Enter value1: 3 Enter
value2: 5 The summation is: 12 The string "Helloooo Nurse!" has 7
vowels and 8 characters that are not vowels. Type -1 to exit. Enter
a number: 2 Enter a number: 3 Enter a number: 10 Enter a number: 32
Enter a number: -1 The average is: 11.75
Sample output for the same input as above using
zyBooks. Part of the output comes from the main method.
Enter string1: Enter value1: Enter value2: The summation is: 12 The string "Helloooo Nurse!" has 7 vowels and 8 characters that are not vowels. Type -1 to exit. Enter a number: Enter a number: Enter a number: Enter a number: Enter a number: The average is: 11.75
//code is explained in comments :
#include <iostream>
#include <string>
using namespace std; // prototypes
int summationBetween(int value1,int value2);
int countVowelsAndOtherCharacters(string string1,int
&numberNonVowels);//you have to pass as reference since it wont
reflect here
double calculateAverage();
int globalValue1=0;
int globalValue2=0;
int main() {
int answer = 0;
int value1 = 0;
int value2 = 0;
double average = 0;
string string1 = "";
int numberVowels = 0;
int numberNonVowels = 0;
cout << "Enter string1: ";
getline(cin, string1);
cout << "Enter value1: ";
cin >> value1;
cout << "Enter value2: ";
cin >> value2;
cout << endl;
cout.setf(ios::fixed);
cout.precision(2);
answer = summationBetween(value1, value2);
cout << "The summation is: " << answer << endl
<< endl;
numberVowels = countVowelsAndOtherCharacters(string1,
numberNonVowels);
cout << "The string \"" << string1 << "\" has "
<< numberVowels << " vowels and ";
cout << numberNonVowels << " characters that are not
vowels. ";
cout << endl; cout << endl;
globalValue1=value1;//you need to assign value1 and
value2 to corresponding global variables as you didnt want to pass
any arguments to functon calculateAverage
globalValue2=value2;
average = calculateAverage();
cout << endl;
cout << "The average is: " << average
<< endl;
return 0;
}
// Function: summationBetween
// This function adds all the numbers between two
numbers. It takes in two integers.
// It adds the starting number and the ending number
into the sum as well.
// The total is returned.
int summationBetween(int value1,int value2){
int sum=0;
for(int
i=value1;i<=value2;++i){//iterate over from value1 to value2
,you have to iterate
sum=sum+i;
}
return sum;
}
// Function: countVowelsAndOtherCharacters
// This function counts the number of vowels and the
number of nonvowels. It takes in a
// string and an integer. It returns the number of
vowels.
int countVowelsAndOtherCharacters(string string1,int
&numberNonVowels){
int
vowelCount=0;
for(int
i=0;i<string1.length();++i){//iterate over passed string
length
if((string1[i]=='A')||(string1[i]=='a')||(string1[i]=='e')||(string1[i]=='E')||(string1[i]=='i')
||(string1[i]=='I')||(string1[i]=='o')||(string1[i]=='O')||(string1[i]=='u')||(string1[i]=='U')){//if
it is a vowel ,increase vowelcount
++vowelCount;
}
}
numberNonVowels=string1.length()-vowelCount;//caluclate non vowel
count
return
vowelCount;
}
// Function: calculateAverage // This function queries
the user for values. It takes in no arguments.
// It returns the average of the numbers.
double calculateAverage(){
return
(globalValue1+globalValue2)/2;//calculateAverage by using 2 global
integers
}
//output:
in c++ Finish the methods in the following code. DO NOT CHANGE THE MAIN METHOD. The...
please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...
// Finish the following program which adds up all integers from 0 to// the user's given number inclusively using a While Loop. The total should be// assigned to the variable 'total'.#includeusing namespace std;int main() {int number;int total = 0;int counter = 0; //initialize the variable// user enters a numbercout << "Enter a positive integer to find the summation of ";cout << "all numbers from 0 to the given number up to 100." << endl;cin >> number;// check for invalid user...
#include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() { char string[100]; char inputChoice, choice[2]; int vowelTotal, consonantTotal; //Input a string cout << "Enter a string: " << endl; cin.getline(string, 100); do { //Displays the Menu cout << " (A) Count the number of vowels in the string"<<endl; cout << " (B) Count...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
#include <iostream> #include <cstring> #include <string> #include <istream> using namespace std; //Function prototypes int numVowels(char *str); int numConsonants(char *str); int main() { char string[100]; char inputChoice, choice[2]; int vowelTotal, consonantTotal; //Input a string cout << "Enter a string: " << endl; cin.getline(string, 100); do { //Displays the Menu cout << " (A) Count the number of vowels in the string"<<endl; cout << " (B) Count...
Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() { cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl; int numOfEmployees = NumOfEmployees(); TotDaysAbsent(numOfEmployees); return 0; } int NumOfEmployees() { int numOfEmployees = 0; cout << "Please enter the number of employees in the company: "; cin >> numOfEmployees; while(numOfEmployees <= 0) { ...
What are the errors in the following code? My professor gave us this prewritten code and asked us to find the errors in it so that it can run properly #include <cstdlib> #include <ctime> #include <iostream> using namespace std; // input: integer // output: none // adds five to the given parameter void addFive( int x ) { x += 5; } // input: none // output: a random number int generateRandomNumber() { srand( time(0) ); return rand() % 100;...
In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task. Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop int cnt = 1; do { cnt += 3; } while (cnt < 25); cout << cnt; It runs ________ times ...
// Write a program that determines how many of each type of vowel are in an entered string of 50 characters or less. // The program should prompt the user for a string. // The program should then sequence through the string character by character (till it gets to the NULL character) and count how many of each type of vowel are in the string. // Vowels: a, e, i, o, u. // Output the entered string, how many of...