Question
Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all .cpp, input and output files for grading.
Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates.
•Write a function called sumOfSquares which takes as its parameter an input file. The function should return the total sum of all the squared numbers in the file up to 0.
•Write function called countMult5, that takes as its parameter an input file. The function should read two integers, start and end, to counts how many numbers between start and end are multiples of 5. Return the answer to the calling function.
•Write a function called printOdd that takes as its parameters an input file stream and output file stream. The function should print only the odd numbers in a file up to -999.
•Write a function called productEven, that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function.
•Define a function called calcAverage, that takes as its parameter an input file. The function should read the numbers from a file up to the sentinel value and calculates their average. Return the answer to the calling function.
•The multiplication operator works by summing some value, x, by another value, y. Write a function definition called multiply that takes two integer parameters to perform the operation described. Return the answer to the calling function.
•Write a function called randCount with no parameters. The function should randomly generate 5 numbers between 8 to 15 and counts how many times a multiple of 2 occurred. Return the answer to the calling function.
•Write a function called summary that takes as its parameters an input and output file. The function should read two integers find the sum of even numbers, the sum of odd numbers, and the cumulative product between two values lower and upper. The function should return the sum of even, odd, ad cumulative product between the lower and upper values.
•Write a function called countConsonants that takes an input file as its parameter. The function should read a word from a file, and a special character. It should count how many vowels and how special characters are in that string. The function should return the vowel and special character count to the calling function.
Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fu


C++ program


you have to creat the input and output files



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

Here is the solution to your question. I tried my best to solve your doubt, however, if you find it is not as good as expected by you. Please do write your further doubts regarding this question in the comment section, I will try to resolve your doubts regarding the submitted solution as soon as possible.

Please give proper indentation as shown in the screenshot.

If you think, the solution provided by me is helpful to you please do an upvote.

Either you have forgotten to upload some files or you have provided incomplete questions. I am not able to find input and output files also some functions of your question are very confusing. Please do clarify in the comments

  1. Write a function called sumOfSquares which takes as its parameter an input file. The function should return the total sum of all the squared numbers in the file up to 0. [Meaning of "up to 0"]
  2. Write a function called printOdd that takes as its parameters an input file stream and output file stream. The function should print only the odd numbers in a file up to -999. [Meaning of "up to -999"]
  3. Define a function called calcAverage, that takes as its parameter an input file. The function should read the numbers from a file up to the sentinel value and calculates their average. Return the answer to the calling function. [Meaning of "sentinel value"]
  4. Write a function called summary that takes as its parameters an input and output file. The function should read two integers find the sum of even numbers, the sum of odd numbers, and the cumulative product between two values lower and upper. The function should return the sum of even, odd, ad cumulative product between the lower and upper values. [use of output_file]
  5. Write a function called countConsonants that takes an input file as its parameter. The function should read a word from a file, and a special character. It should count how many vowels and how special characters are in that string. The function should return the vowel and special character count to the calling function. [read a word or read all words of the input file]

However, based on your provided information below is the solution to your problem.

1. 2. 3. #include <iostream> #include<fstream> #include<cstdlib> #include<ctime> #include<cctype> using namespace std; 4. 5.
#include <iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<cctype>
using namespace std;


int sumOfSquares(string input_file)
{
    fstream file;
    int number;
    int sum=0;
    file.open(input_file.c_str());
    while(file>>number)
    {
        sum+=(number*number);
    }
    file.close();
    return sum;
}

int countMult5(string input_file,int start,int end)
{
    fstream file;
    int number;
    int count=0;
    file.open(input_file.c_str());
    int index=0;
    while(file>>number && index>=end)
    {
        if(index>=start && index<end)
        {
            if(number%5)
                count+=1;
        }
        index+=1;
    }
    file.close();
    return count;
}

void printOdd(string input_file, string output_file)
{
    fstream file,ofile;
    int number;
    file.open(input_file.c_str());
    ofile.open(output_file.c_str());
    while(file>>number)
    {
        if(number<=999 && number%2==1)
            ofile<<number<<" ";
    }
    file.close();
}


int productEven(string input_file,int low,int high)
{
    fstream file;
    int number;
    file.open(input_file.c_str());
    int product=1;;
    while(file>>number)
    {
        if(number>=low && number<=high && number%2==0)
        {
            product*=number;
        }
    }
    file.close();
    return product;
}


float calcAverage(string input_file)
{
    fstream file;
    int number;
    int sum=0;
    int count=0;
    file.open(input_file.c_str());
    while(file>>number)
    {
        count+=1;
        sum+=(number*number);
    }
    file.close();
    float avg=((float)(sum))/count;
    return avg;
}

int multiplication(int x, int y)
{
    int product=0;
    for(int i=0;i<y;i+=1)
    {
        product+=x;
    }
    return product;
}


int randCount()
{
    srand(time(0));
    int count=0;
    for(int i=0;i<5;i+=1)
    {
        if(((rand()%(15-8))+8)%2==0)
        {
            count+=1;
        }
    }
    return count;
}


int summary(string input_file, string output_file)
{
    int lower,upper;
    cout<<"Enter the lower value: ";
    cin>>lower;
    cout<<"Enter the upper value: ";
    cin>>upper;
    fstream file;
    int number;
    int sum=0,sumE=0,sumO=0,product=1;
    file.open(input_file.c_str());
    while(file>>number)
    {
        if(number>=lower && number<=upper)
        {
            if(number%2==0)
                sumE+=number;

            if(number%2==1)
                sumO+=number;
            product*=number;
        }
    }
    sum=sumE+sumO+product;
    file.close();
    return sum;
}

int countConsonants(string input_file)
{
    fstream file;
    file.open(input_file.c_str());
    char ch;
    cout<<"Enter the special character: ";
    cin>>ch;
    string word;
    int count=0;
    while(file>>word)
    {
        for(int i=0;i<word.length();i+=1)
        {
            if(toupper(word[i])=='A' || toupper(word[i])=='E' || toupper(word[i])=='I' || toupper(word[i])=='O' || toupper(word[i])=='U' || word[i]==ch)
            {
                count+=1;
            }
        }
    }
    return count;
}


int main() 
{
    string input_file,output_file;
    cout<<"Enter the input file name: ";
    cin>>input_file;
    cout<<"Enter the output file name: ";
    cin>>output_file;
    int start,end;
    cout<<"Enter the start value: ";
    cin>>start;
    cout<<"Enter the end value: ";
    cin>>end;
    cout<<sumOfSquares(input_file)<<endl;
    cout<<countMult5(input_file,start,end)<<endl;
    printOdd(input_file,output_file);
    cout<<productEven(input_file,start,end)<<endl;
    cout<<calcAverage(input_file)<<endl;
    cout<<multiplication(start,end)<<endl;
    cout<<randCount()<<endl;
    cout<<summary(input_file,output_file)<<endl;
    cout<<countConsonants(input_file)<<endl;
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Note: The order that these functions are listed, do not reflect the order that they should...
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
  • Please Use C++ for coding . . Note: The order that these functions are listed, do...

    Please Use C++ for coding . . Note: The order that these functions are listed, do not reflect the order that they should be called. Your program must be fully functional. Submit all.cpp, input and output files for grading. Write a complete program that uses the functions listed below. Except for the printodd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

  • •The multiplication operator works by summing some value, x, by another value, y. Write a function...

    •The multiplication operator works by summing some value, x, by another value, y. Write a function definition called multiply that takes two integer parameters to perform the operation described. Return the answer to the calling function. •Write a function called randCount with no parameters. The function should randomly generate 5 numbers between 8 to 15 and counts how many times a multiple of 2 occurred. Return the answer to the calling function. •Write a function called summary that takes as...

  • Write a function in the C++called summary that takes as its parameters an input and output...

    Write a function in the C++called summary that takes as its parameters an input and output file. The function should read two integers find the sum of even numbers, the sum of odd numbers, and the cumulative product between two values lower and upper. The function should return the sum of even, odd, ad cumulative product between the lower and upper values. Please write program in C++.

  • Write a function called productEven that takes as its parameter an input file. The function should...

    Write a function called productEven that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function. c++ program

  • please write program in C++ Write a function called productEven, that takes as its parameter an...

    please write program in C++ Write a function called productEven, that takes as its parameter an input file. The function should read two integers and calculate the total product of only even numbers between them. Return the answer to the calling function. please write the program in C++

  • in Java and also follow rubric please 4. Write a complete program to do the following:...

    in Java and also follow rubric please 4. Write a complete program to do the following: Using an input and output files, write a program that will read 20 numbers from an input file called InFile. Sum all even numbers and multiply all odd numbers. Print the numbers read from the input file to an output file called OutFile. Also print the sum of the even numbers and the product of the odd numbers to the output file. Rubric: •...

  • FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data...

    FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • Please write program in C++ Write a function called randCount with no parameters. The function should...

    Please write program in C++ Write a function called randCount with no parameters. The function should randomly generate 5 numbers between 8 to 15 and counts how many times a multiple of 2 occurred. Return the answer to the calling function. please write the program in C++

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