Answer to Question #212759 in C++ for Aby

Question #212759

Write a main program to test the following functions:

void introduction() ;         // to display a text to tell what is the program about

bool keepRunning();           // to ask the user for more times to run the program

void ruuProgram();          // to input an array, calculate series (k=0 to n) a^2*[k]

1
Expert's answer
2021-07-02T04:11:37-0400
#include <iostream>
using namespace std;
void introduction(){
    cout<<"\n********************************\n";
    cout<<"Calculates series (k = 0 to n) a^2*a[k]\n";
}
bool keepRunning(){
    int x;
    cout<<"\nRun the program again?\n0. No\n1. Yes\n";
    cin>>x;
    return x;
}
void ruuProgram(){
    cout<<"Input size of array: ";
    int n; cin>>n;
    cout<<"Input elements of the array\n";
    int *a = new int[n], sum = 0;
    for(int k = 0; k < n; k++){
        cin>>a[k];
        sum += a[0] * a[0] * a[k];
    }
    cout<<"\nResult of the series: "<<sum<<endl;
    delete a;
}
int main(){
    do{
        introduction();
        ruuProgram();
    }while(keepRunning());
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS