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

C program to reverse the elements of array, C program to reverse the elemen...

C program to reverse the elements of array: #define rows 3 #define cols 3 void main() {                 int i=0,j=0;                 int arr[rows][cols];

Wap to print series from 1 to 10 & find its square and cube, # include stdi...

# include stdio.h> # include conio.h> # include math.h>   void main () { int a=1,sqr=0,cube=0; clrscr (); while (a { sqr=pow(a,2); cube=pow(a,3);

Probabilistic hough transform, Two kinds of line detection are implemented ...

Two kinds of line detection are implemented in OpenCV, the Hough Transform and the probabilistic Hough transform. Assume that there are n feature points in an image and that it tak

Program in rpeanut that fills the graphics display, Write a program that co...

Write a program that counts from 0 to 99 and prints these numbers to the terminal ie it prints 00, 01, 02, 03, 04, 05, ....,99. Graphics 1. Write a program in rPeANUt that

Program to list the cities and their states, The program will ask the user ...

The program will ask the user to enter: '1' to List the cities(and their state abbrev)  from largest to smallest (by their population) with their population '2'  to List the

Loop statement, write a c++ program to accept 3 numbers and find the larges...

write a c++ program to accept 3 numbers and find the largest of 3 numbers

How to implement tr- 069 protocol, Description - The TR-069 CPE WAN Managem...

Description - The TR-069 CPE WAN Management Protocol (CWMP) is a protocol that was created by the Broadband Forum (formally the DSL Forum) which sets out a common method for CPE de

Logic families and lsi devices, We have used logic symbols in the past, but...

We have used logic symbols in the past, but not really though about the actual real devices. Semiconductor companies have taken the logic symbols are manufactured them into logic f

String routines in c, Available in the string.h header file are the followi...

Available in the string.h header file are the following routines         strcat(string1,string2);   This joins string2 to string1; care must be taken to allocate enough space for

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