Computer Science, asked by dibyendu16, 7 months ago

[tex]<b><body\:bgcolour="skgblue">[tex]
[tex]<marquee direction="left" style="background:yellow"">{100 Points}</marquee>[tex]


Write a program to create a class Force with the data members / instance variables M (to store mass of an object) and A (to store the acceleration). Define a method void Input( int ma, int ac) to assign parameters 'ma' to M and 'ac' to A. Another method double calculate( ) to calculate the force value after doing the calculation( force = Mass x acceleration) and return force value. Also define main method to accept the mass value of an object and acceleration value. Create suitable object of the class and call the functions/ methods t2​

Answers

Answered by tapatidolai
1

Answer:

Remember: a class describes what an object knows and what an object does

A class is the blueprint for an object. When you write a class, you’re describing how the JVM should make an object of that type. You already know that every object of that type can have different instance variable values.

Every instance of a particular class has the same methods, but the methods can behave differently based on the value of the instance variables.

The Song class has two instance variables, title and artist. The play() method plays a song, but the instance you call play() on will play the song represented by the value of the title instance variable for that instance. So, if you call the play() method on one instance you’ll hear the song “Politik”, while another instance plays “Darkstar”. The method code, however, is the same.

Answered by Anonymous
0

#include<iostream.h>

#include<conio.h>

class Force

{

float M;

float A;

public:

void Input(int ma,int ac)

{

M=ma;

A=ac;

}

double calculate ( )

{

return MxA;

};

void main( )

{

clrscr();

Force obj1;

obj1.Input(2,3);

cout<<" Force="<<obj1.calculate();

getch();

}

_______________________________

happy coding :)

Similar questions