Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will have three functions (printStars, addThem and main): T

ID: 3914725 • Letter: W

Question

Write a program that will have three functions (printStars, addThem and main): The first function should be named printStars and will output five stars on a single line. The second function should be named addThem and will accept two numbers (passed as arameters) and return the sum. Finally, the main function will: 1) ask the user to input two numbers 2) call the addThem function that will return the sum, and then 3) execute a loop that will call the printStars function the number of times returned by th addThem function.

Explanation / Answer

Below is the solution:

#include <iostream>
using namespace std;
void printStars(int); //function declaration of printStars(int)
double addThem(double, double); //function declaration of addThem(double,double)

int main() {
   printStars(5); //printStars funtion to print the star
   double num1,num2,sum; //declare variable num1 and num2 for input two number and sum for sum of inputed two number
   cout<<"Enter Two Numbers"; //ask to enter two number
   cin>>num1>>num2; //enter two number
   sum = addThem(num1,num2); //store the addThem function value to sum variable
   cout<<"The sum is: "<<sum; //prints the sum value
   cout<<endl;
  
   for(int i=0; i<sum; i++) //for loop to print 5 star 5 times
   {
       printStars(5); //call printStars function
   }
   return 0;
}

//function defination
void printStars(int star) //printStars function
{
   for(int i=0; i<star; i++) //for loop to prints the star five times
   {
       cout<<"*";
   }
   cout<<endl;
}

double addThem(double number1, double number2) //addThem function to add the inputed two number
{
   return number1+number2; //return number after adding them
}

sample output:

*****
    Enter Two Numbers: 4 6
    The sum is: 10
    *****
    *****
    *****
    *****
    *****
    *****
    *****
    *****
    *****
    *****

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote