Question

Help with these questions

A function rectarea has already been defined with this prototype: int rectarea(int width); It collects an integer height fromThe variable age has been defined as an integer. Write code which will print the age in two years. For example: Test Result a

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

#include<iostream>
using namespace std;
//this function used to calculate the area of rectangle
int rectarea(int width)
{
   //prompt the user to enter the height
   cout<<"Enter height of rectangle:\t";
   int height;
   cin>>height;
   //calculate the area using the formula
   int area = width * height;
   //return area to the function call
   return area;
}
int main()
{
   //call the function with width 5
   int area1 = rectarea(5);
   //print the area
   cout<<"Area of the rectangles is "<<area1<<endl;
   //call the function with width 10
   int area2 = rectarea(10);
   //print the area
   cout<<"Area of the rectangle is "<<area2<<endl;
   //initialize the age variable to 5
   int age = 5;
   //print the age after two years
   cout<<"The age will be "<<age + 2<<" in two years"<<endl;
  
}

Activities Terminal Tue 23:54 deepika@deepika-TravelMate-P243-M: -/Desktop File Edit View Search Terminal Help deepika@deepikIf you have any doubts please comment and please don't dislike.

Add a comment
Know the answer?
Add Answer to:
Help with these questions A function rectarea has already been defined with this prototype: int rectarea(int...
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 C An array ints of integers has already been declared and initialized. A function printint...

    In C An array ints of integers has already been declared and initialized. A function printint has been defined with the following prototype: void printint(int *); Write code that will call printint with a pointer to the second value in the array ints. Note: you will not need to declare an int variable.

  • C program help 4. Write a function called scan_hex. Here is its prototype: void scan_hex(int *xptr);...

    C program help 4. Write a function called scan_hex. Here is its prototype: void scan_hex(int *xptr); Here is an example of its use, in conjunction with print_decimal. Assume that the user will type a non-negative hex number as input. Also, assume that the “digits” a-f are in lower case. Let’s say the user types 1b int x; scan_hex(&x); print_decimal(x); MODIFY THIS CODE // function inputs a non-negative integer and stores it into *xptr. // The format of the input is...

  • Question 1 Answer the questions below about this function prototype: double coinTotal (double coinValue, int nCoins);...

    Question 1 Answer the questions below about this function prototype: double coinTotal (double coinValue, int nCoins); What is the type of the return value?   How many parameters does the function take? What is the name of the function? Question 2 These are defined in the function heading and tell a user what data needs to be sent to a function. Question 3 What is the term used for a variable sent as data in a function call, such as n1...

  • Write in C: Assume that an int variable age has been declared and already given a...

    Write in C: Assume that an int variable age has been declared and already given a value and assume that a char variable choice has been declared as well. Assume further that the user has just been presented with the following menu: S: hangar steak, red potatoes, asparagus T: whole trout, long rice, brussel sprouts B: cheddar cheeseburger, steak fries, cole slaw (Yes, this menu really IS a menu!) Write some code that reads a single character (S or T...

  • Please solve this in Java. Assume we have already defined a variable of type int called...

    Please solve this in Java. Assume we have already defined a variable of type int called num with the following line of code: int num = ???; // 'num' can have any int value TASK: Print a Triforce composed of 3 centered triangles created with num asterisks (*) on the bottom row, num - 2 asterisks on the next bottom row, ..., and 1 asterisk on the top row, and such that the triangles are surrounded by hyphens (-). You...

  • Assuming that the array upc declared below has already been filled with MAX_LENGTH values, write a...

    Assuming that the array upc declared below has already been filled with MAX_LENGTH values, write a function that will ask to input an integer from the keyboard and perform a sequential search of the array for the input integer. If the input integer is found, print the index of the matching value in the array. Otherwise, print "Not found". Include declarations for all variables that you use.             const int MAX_LENGTH = 25;             int upc[MAX_LENGTH]; Please write in C++

  • *Please write in code in C* First, write a function called prime_check(int x) that takes an...

    *Please write in code in C* First, write a function called prime_check(int x) that takes an integer number as an input then return 1 if it is a prime number nd returns 0 if it is a composite number Then, Write a program that prompt the user to input two numbers: Print the multiplication of these two numbers if both of them are prime. Or Print " Sorry at least one of your number is composite" if otherwise

  • A student has written the following user-defined function to compute the total cost of a dinner...

    A student has written the following user-defined function to compute the total cost of a dinner for some number of guests. The parameters for this function are the cost per meal (a double) and the number of guests (an integer). There seem to be some errors in the code--what are they? Code written by the student: int dinnerCost ( double mealCost, guests) int total = mealCost * guests; The student failed to declare the datatype of guests as int in...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • 3 Given that somebody has already defined the required structs represent a road map as a...

    3 Given that somebody has already defined the required structs represent a road map as a graph, like this: to struct town string name; int distance; roadlink roads; ) struct roadlink int length; town whereto; roadlink next; ) s you can see, the programmer chose not to give each town a vector for the roads that le ad from it, but a linked list instead. Each roadlink at it leads to. The programmer has even written the code that correctly...

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