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
mixas84 [53]
3 years ago
14

Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour

and minute data members. Write a single C statement to create an object of the Timer class using dynamic memory allocation and assign it to a pointer variable named timePtr. It should call the constructor with two parameters. Use values of 10 and 20 for hour and minute respectively. b) Write the definition for a function named randArray that takes a single integer argument, n, and returns a dynamically allocated array of n pseudo-random integers. You may assume the pseudo-random number generator has been previously declared and seeded. (i.e. you do not need srand(time(0)) or an include.) c) Now write C statements to call the randArray function to construct a 100 element array, then print the array values to the display (one per line) and delete the dynamically allocated array.
Computers and Technology
1 answer:
klemol [59]3 years ago
8 0

Answer:

Check the explanation

Explanation:

a) there is a need to create an allocated object of dynamic ability for the Timer class, and assign it to a pointer variable timePtr.

As we are going to create an object of timer class, so timePtr will be a pointer of type timer class. Hence, left side of the statement will be as follows.

Timer* timePtr

Now, to create an object in a dynamic way, we use new operator in C++. And at last, we need to call the constructor to create the object. So, the full statement will be as follows:

                        Timer* timePtr = new Timer (10, 20);

b)

//c++ code : a:

#include <iostream>

using namespace std;

class Timer

{

public:

int hr;

int minute;

Timer(int h,int min)

{

h=h+min/60;

min=min%60;

hr=h;

minute=min;

}

};

int main()

{

Timer *t=new Timer(10,20);

cout<<"Time : "<<t->hr<<" hr :"<<t->minute<<" min"<<endl;

return 0;

}

c)

//c++ code for b, c:

#include <iostream>

#include <stdlib.h>

#include <time.h>

using namespace std;

int* randfun_alloc(int n)

{

srand (time(NULL));

int *arr=new int[n];

for(int i=0;i<n;i++)

arr[i]=rand()%1000;

 

return arr;

}

int main()

{

int n;

cin>>n;

int *arr =randfun_alloc(n);

 

for(int i=0;i<n;i++)

cout<<arr[i]<<" ";

 

cout<<endl;

delete[] arr;//delete the allocated array

return 0;

}

Documents: bash Konsole File Edit View Bookmarks Settings Help raushan-HP-2000-Notebook-PC /Documents > g++ randarr.c

You might be interested in
A pointing device uses light to determine hand motion.
kirill [66]
The answer to this is Optical mouse. 

The reason the answer is optical mouse is because the optical mouse is a computer mouse which uses a light source, typically a light-emitting diode, and a light detector, such as an array of photodiodes, to detect movement relative to a surface. 

Hope this helped :)
have a great day 
3 0
3 years ago
Who is a software engineer
kolbaska11 [484]

Answer:

it is correct answer

please follow me

if you understand it

6 0
3 years ago
Read 2 more answers
____ is a broadband wireless transmission technology that is based upon a series of IEEE standards.​
dedylja [7]

Answer:

"WiMAX" is the correct answer for the above question.

Explanation:

  • WiMAX is a broadband wireless technology that follows the IEEE standard. This full form of this technology is "Worldwide Interoperability for Microwave Access".
  • This technology is used to control the media and provide the physical layer.
  • The above question asked about the term which follows the IEEE standard. So the term is "Wimax"

3 0
4 years ago
What does dual dimensioning mean?
Westkost [7]

Answer:

C. use of multiple units of measure for a dimension.

Explanation:

Measurements refers to the process which typically involves the process of identifying and determining the dimensions of a physical object. The dimensions include important parameters such as width, height, length, area, volume, circumference etc.

Dual dimensioning can be defined as the use of multiple units of measure for a dimension. Thus, dual dimensioning comprises of two (2) sets of units (values) of measurement such as meters and centimeters, millimeters and inches etc., in a dimension.

The main purpose of dual dimensioning is to aid understanding and for easy conversion purposes.

7 0
3 years ago
Which of the following statements is/are true? (Points : 2) A. Objects communicate through message passing.
damaskus [11]

Answer:

In the given question option A and C are true.

Explanation:

In object-oriented programming languages (oops).We use the class object concept. As we know the class is a collection of data member and member function and class provide a blueprint for an object. it is a real-time entity. An object is created from a class. So the option "B" is not true, because first, we create the class we create an object of that class. Option"D" is not true because we implement class by the object, not by interface.

Only option "A and c is true".

7 0
4 years ago
Other questions:
  • The set of communications rules for exchanging information electronically on the internet is called the ________.
    10·1 answer
  • How do you insert a new row into a worksheet
    5·1 answer
  • Which of the following best describes Roblox?
    12·2 answers
  • A relative path name defines a path from_________________________ Select one: a. from the UFD (user file directory) b. the curre
    6·1 answer
  • One problem with using e-mail is that ______.
    14·2 answers
  • What does the action tool allow you to do in Microsoft Powerpoint?
    15·1 answer
  • Python: initalize the variable first_name with the value from the user prompt "What is your first name? " initalize the variable
    9·1 answer
  • Choose the answer that best completes the statement.
    7·2 answers
  • In the space provided, analyze the pros and cons of becoming a member of an artistic guild. Your answer should be at least 150 w
    12·1 answer
  • Is there a way to delete a question on brainly?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!