1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Fantom [35]
4 years ago
6

Can we have both object and loop in the same program? explain in detail with example. In c++

Computers and Technology
1 answer:
alex41 [277]4 years ago
4 0

Answer:

The answer to this question is "yes" and the program to this question can be given as:

Program:

#include <iostream> //include header file

using namespace std; //using namespace

class ab //define class

{

public: //access modifier

int i,tab; //defining variable.

void table(int n) //define method

{  

for(i=1; i<=10; i++) //define loop.

{

   tab=n*i; //calculate table.

   cout<<tab<<endl; //print values.

}

}

};

int main() //define main method.

{

int n; //defining variable

cout<<"Enter any number :"; //message

cin>> n; //input number by user.  

cout<<"Table of :" <<n<<endl; //message

ab ob; //creating class object.

ob.table(n); //calling function.

return 0;

}

Output:

Enter any number :2

Table of :2

2

4

6

8

10

12

14

16

18

20

Explanation:

  • In the above c++ program firstly defines a class that is "ab" inside the class two integer variable is defined that is " i and tab".  
  • Then a function that is table() is defined, which takes a value n in its parameter. This function doesn't return any value. Inside the function, a for loop is define that calculates the table of the given number and prints its value.  
  • In the main method, an integer variable n is defined that takes value-form user and pass into the function. In the main method, we create the class object that is "ob" and with the help of an object we call the function that prints table of a given number.
You might be interested in
A drowsy cat spots a flowerpot that sails first up and then down past an open window. The pot is in view for a total of 0.50 sec
GaryK [48]

Answer:

2.342m

Explanation:

Given

Time = 0.5 s

Height of Window = 2m

Because the pot was in view for a total of 0.5 seconds, we can assume that it took the cat 0.25 seconds to go from the bottom of the window to the top

Using this equation of motion

S = ut - ½gt²

Where s = 2

u = initial velocity = ?

t = 0.25

g = 9.8

So, we have.

2 = u * 0.25 - ½ * 9.8 * 0.25²

2 = 0.25u - 0.30625

2 + 0.30625 = 0.25u

2.30625 = 0.25u

u = 2.30625/0.25

u = 9.225 m/s ------------ the speed at the bottom of the pot

Using

v² = u² + 2gs to calculate the height above the window

Where v = final velocity = 0

u = 9.225

g = 9.8

S = height above the window

So, we have

0² = 9.225² - 2 * 9.8 * s

0 = 85.100625 - 19.6s

-85.100625 = -19.6s

S = -85.100625/19.6

S = 4.342

If 4.342m is the height above the window and the window is 2m high

Then 4.342 - 2 is the distance above the window

4.342 - 2 = 2.342m

6 0
3 years ago
A thermogram taken outside a house shows high amounts of thermal energy around the windows but not around the roof. which conclu
mestny [16]

The conclusion sustains the thermogram will be that the windows are not energy efficient, but the roof stands energy efficient.

<h3>What is Thermography?</h3>

Thermography exists a noninvasive method that employs an infrared camera to develop pictures that depict patterns of heat and blood flow on or around the body's surface. A thermogram taken outside a house shows high quantities of thermal energy around the windows but not around the roof. The conclusion that supports the thermogram will be that the windows are not energy efficient, but the roof exists energy efficient.

Thermal energy (also named heat energy) is produced when a rise in temperature pushes atoms and molecules to move faster and collide with each other. The energy that reaches the temperature of the heated substance is named thermal energy. The term "thermal energy" exists utilized loosely in various contexts in physics and engineering. It can guide several different well-defined physical concepts.

To learn more about Thermography refer to:

brainly.com/question/1500896

#SPJ4

The complete question is,

A thermogram taken outside a house shows high amounts of thermal energy around the windows but not around the roof.

Which conclusion supports the thermogram?

The windows and the roof are energy efficient.

The windows and the roof are not energy efficient.

The windows are not energy efficient, but the roof is energy efficient.

The windows are energy efficient, but the roof is not energy efficient.

4 0
1 year ago
What is the main difference between inserting header/footer in excel and word?​
irina [24]

Answer:

A header is at the top of the page and used for titles and epicas. The footer is used for footnotes or page numbers

8 0
3 years ago
Who are The Boys? EddieVR, YourNarrator, JoshDub, Mully, and last but most certainly not least, Juicy(FruitSnacks). Green gang o
malfutka [58]

Answer:

yes or no

Explanation:

6 0
3 years ago
Nathan notices his computer system is slowing down when he tries to copy documents to it. He also gets a prompt that warns him t
vesna_86 [32]
You would replace the hard drive
3 0
3 years ago
Other questions:
  • 8.17 Lab: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, th
    15·1 answer
  • When should students practice netiquette in an online course? Check all that apply.
    14·2 answers
  • Documentation for evidence which includes exactly what, when, and from whom evidence was collected, the condition of this eviden
    6·1 answer
  • What are the overheads associated with recursive algorithms? [
    9·1 answer
  • What is a systems development life cycle?
    5·1 answer
  • Write the definition of a function named max that receives an int parameter and returns the largest value that it has been calle
    12·1 answer
  • What is output? Select all that apply. c = 3 while (c &lt; 10): c = c + 2 print (c)
    6·1 answer
  • What is 4x+2x(-3-3) thanku
    11·2 answers
  • Functions of light pen​
    9·1 answer
  • After Sally adds the Print Preview and Print command to the Quick Access Toolbar, which icon would she have added? the icon that
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!