Objects as function arguments, C/C++ Programming

Assignment Help:

Objects as Function Arguments:

In C program there are several methods to define arguments, and in some case even a

structure can be approved as an argument.  Similarly in C++ in place of structure an object can be defined as an argument.

 

class interest

{

float i,p,n,r,a;

 

public:

void getdata(int gp, int gn, int gr);

void putdata(void)

{cout<<"Interest is "<

cout<<"Amount is "<

}

void suminterest(interest,interest);

};

void interest::getdata(int gp,int gn, int gr)

{p=gp;n=gn;r=gr;

cout<<"Enter Principal: "<<"\n";

cin>>p;

cout<<"Enter Year: "<<"\n";

cin>>n;

cout<<"Enter Rate: "<<"\n";

cin>>r; i=(p*n*r)/100; a=p+i;

}

void interest::suminterest(interest i1, interest i2)

{i=i1.i+i2.i;

a=i1.a+i2.a;      }

 

int main()

{clrscr();

interest i1,i2,i3; // Created three objects

i1.getdata(  1000,10,2); //Calculates interest and amount for object i1.

i1.putdata();

i2.getdata(10000,8,3); //Calculates interest and amount for object i2.

i2.putdata();

i3.suminterest(i1,i2); ////Total interest and amount from object i1 and i2.

i3.putdata();

return 0;

}


Related Discussions:- Objects as function arguments

Program to display the greatest common divisor , Many modern cryptography a...

Many modern cryptography algorithms require two numbers that are coprime, or sometimes referred to as relatively prime. Two numbers are coprime if their greatest common divisor is

Define a function in c program, Define a function in c program: int f1...

Define a function in c program: int f1() { static int x=10; return x; } int f2() { int y=5; return y; } extern int z; void f()     {

Template class and class template in c++, Differentiate between a template ...

Differentiate between a template class and class template in C++? Ans) Template class: A generic definition or a parameterized class not instantiated until the client gives the

Coding, Problem Statement: You have to write a C program to develop a Car P...

Problem Statement: You have to write a C program to develop a Car Parking Management System for a busy commercial area. The system will record the car plate number, date and time w

Develop a windows application to show computer hardware, - But with less fe...

- But with less features and more user-friendly (particularly for non-tech savvy users). - Software needed having a left menu with links (no pictures required) for every hardwar

Area under curve, write a program to find the area under the curve y=f(x) b...

write a program to find the area under the curve y=f(x) between x=a and x=b integrate y=f(x)   #include float start_point, /* GLOBAL VARIABLES */

Write a function that computes the total interest charged, You are going to...

You are going to write a function that computes the total interest charged on a credit card before it is paid off. List all the inputs the function will need.

Write Your Message!

Captcha
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