Question
(Hand written if possible) Q.2. Write C++ code for the following: a) Heres a function: int times2(int a) { return (a*2); } Write a main
(Hand written if possible)
Q.2. Write C++ code for the following:
a) Heres a function: int times2(int a) { return (a*2); } Write a main () program that includes everything necessary to call this function.
b) Raising a number n to a power p is the same as multiplying n by itself p times. Write a function called power () that takes a double value for n and an int value for p, and returns and display the result as a double value. Write a main () function that gets values from the user to test this function.
c) A phone number, such as 051 1212123, can be thought of as having two parts: the area code (051) and the number (1212123). Write a program that uses a structure to store these two parts of a phone number separately. Call the structure phone. Create two structure variables of type phone. Initialize one (suppose it has been initialized as 051 1111111. This is just for example, you can change it), and have the user input a number for the other one. Then display both numbers.
HINT: The interface/communication might look like this: Enter your area code: 051 Enter your number: 042 45454545 The stored/initialized number is: 051 1111111 Your entered number is 042 45454545
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started