Raising a number n to a power p is the same as multiplying n

Assignment Help C/C++ Programming
Reference no: EM131089274

Program :-1

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 the result as double value. Use a default argument of 2for p, so that if this argument is omitted the number will be squared. Write a main () function
That gets values from the user to test this function.

Program :- 2

A point on the two dimensional plane can be represented by two numbers: an X coordinate and a Y coordinate. Foe example (4,5) represents a point to the right of the origin along with the X axis and 5 units up the Y-axis. The sum of two points can be defined as a new point whose X coordinate is the sum of the X coordinates of the points and whose Y coordinate is the sum of their Y coordinates.

Write a program that uses a structure called point to model a point. Define three points and have the user input values to two of them. Than set the third point equal to the sum of the other two and display the value of the new point. Interaction with the program might look like this:

Enter coordinates for p1: 3 4
Enter coordinates for p2: 5 7
Coordinates of p1+p2 are:8,11

 

Program :- 3

Create the equivalent of a four function calculator. The program should request the user to enter a number an operator and another number. It should then carry out the specified arithmetical operation: adding, subtracting, multiplying or dividing the two numbers (it should use a switch statement to select the operation). Finally it should display the result.

When it finishes the calculation, the program should ask if the user wants to do another calculation. The response can be ‘Y' or ‘N'. some sample interaction with the program might look like this.

Enter first number, operator, and second number.10/3
Answer=3.333333
Do another (Y/N)? Y
Enter first number, operator, and second number 12+100
Answer=112
Do another (Y/N)? N


Program :-4

A phone number such as (212) 767-8900 can be thought of as having three parts: the area code (212), the exchange (767) and the number (8900). Write a program that uses a structure to store these three parts of a phone number separately. Call the structure phone. Create two structure variables of type phone. Initialize one and have the user input a number for the other one. Then display both numbers. The interchange might look like this:

Enter your area code, exchange and number; 415 555 1212
My number is (212) 767-8900
Your number is (415) 555-1212

Program :- 5

Create two classes DM and DB which store the value of distances. DM stores distances in meters and centimeters and DB in feet and inches. Write a program that can read values for the class objects and add one object of DM with another object of DB.

Use a friend function to carry out the additional operation. The object that stores the result may be a DM object or DB object depending on the units in which the results are required. The display should be in the format of feet and inches or meters and centimeters depending on the object on display.

Program 6

Create a class Rational which represents a numerical value by two double values-NUMERATOR & DENOMINATOR .Include the following Public member Functions:
? Constructor With no Arguments
? Constructor with two arguments
? Void reduce() tha reduces the rational nuber by eliminating the hightest commom factor between the numeratorand denominator
? Overload +operator to add two rational number.
? Overload >>operator to enable input through cin.
? Overload << operator to enable output through cout

Write a main() to test all thje functions in the class.


Program :-7


Consider the following class definition

Class father
{
Protected:
int age;
public:
father (int x) {age=x;}

virtual void iam ()
{
Cout<<"I AM THE FATHER, my age is:"<age<<endl;}
};

Derive the two classes son and daughter from the above class and for each, define iam() to write our similar but appropriate messages. you should also define suitable constructors for these classes.

Now write a main() that creates objects of the three and then calls iam() for them .Declare pointer and in each case call iam() through the pointer to demonstrate polymorphism in action.

 

Reference no: EM131089274

Questions Cloud

Capital asset pricing model-the required rate of return : The stock of Verde Enviro-Systems has a beta of 1.9. If the current risk-free rate is 3% and the market risk premium is 5% then according to the Capital Asset Pricing Model, what should be the required rate of return (report as a percentage, i.e. 11...
Sell off enough of fixed assets at book value : Weber interstate paving co had 450 million of sales and 225 million of fixed assets last year, so its FA/sales ratio was 50%. However, its fixed assets were used at only 65% of capacity. If the company had been able to sell off enough of its fixed as..
Write a program that creates a binary file : Write a program that creates a binary file by reading the data for the students from the terminal .The data of each student consist of roll no. ,name ( a string of 30 or lesser no. of characters ) and marks.
Analysts have estimated that magnetek dividend : Magnetek Corp has just paid a dividend of $2 per share and you are now considering purchasing this stock. Analysts have estimated that Magnetek's dividend will grow at 4% per year in perpetuity. Given the riskiness of Magnetek stock, shareholders' re..
Raising a number n to a power p is the same as multiplying n : 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 the result as double value. Use a default argument of 2for p, so that ..
What is the market price per share of stock : Say you decide to start a firm and you need $500 million of capital to begin. You sell stock for its par value, a total of one million shares (par value is $200 per share), and sell $300 million of bonds at par value. You use the capital you just rai..
Recently issued bond with the characteristics : Duke Energy has recently issued a bond with the following characteristics: maturity: 20 years, coupon rate: 8% (paid semi-annually), face value: $1000. Your investment advisor has told you that the yield-to-maturity on this bond is 7.5%. What should ..
The review of bapsi sidhwa ice candyman : Give an introduction to the review of Bapsi Sidhwa's Ice Candyman, as a Parsi novel
According to the pecking order hypothesis : According to the Pecking Order Hypothesis, what is the sequence of sources of funds that a firm will typically access when obtaining capital for additional investments

Reviews

Write a Review

C/C++ Programming Questions & Answers

  C++ program that takes temperature as input

Create a C++ program that takes temperature as input and provides as output your sports decision. Assume that temperatures are only expressed as integers. In the program, include 2 void functions titled getTemp and printActivity, each with an int ..

  Write a function named shift_right

The function should make sure that left is less than or equal to right, and that distance is greater than zero. If either of these conditions fails, the function should return the value 1 to indicate an error.

  An array-based queue for bcs registration

objective of this assignment is to use C++ to queue studentsinto an array-based queue for BCS registration. Students have the option of taking five different courses, but each course can only hold 8 students.

  Questions related to c programming

Which statement will read a floating point value from the keyboard and store it in the variable x? A. printf("float = %f", x); B. scanf("%f", &x); C. scanf("&f", %x); D. scanf("%d", &x);

  Program that asks the user to enter the monthly costs

write a program that asks the user to enter the monthly costs for the following expenses incurred from operating his or her automobile:

  Program that opens a file representing an encoded maze

Write a C++ program that opens a file representing an encoded maze and reads it in properly so it can be analyzed.

  How do you access the memory address of a variable

How do you access the memory address of a variable? How do you access the contents of the memory location whose address is stored in a pointer variable?

  Generate the output below using the function

Make a C program that will generate the output below using the function that will pass the value into the function.

  Create an array of customer names

In preparation for more complex data processing tasks using object-oriented objects that you will create in up-coming units, in this unit you will utilize arrays to build some basic processing logic and structures.

  Determines how many breaths a person has had in their life

Develop and test a program that determines how many breaths and how many heartbeats a person has had in their life. The average respiration (breath) rate of people varies with age.

  What will be the output of the program

what will be the output of the program?

  Prompt the user to enter the price for each vegetable

Let us consider a simple grocery store with just 5 products. Assume that all items are sold by weight. Select 5 vegetables to use in the program.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd