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
software that instructs the computer how to run applications and controls the display/keyboard is know as the___.
kakasveta [241]
The answer is the alu arithmetic logic unit.
8 0
4 years ago
A graphic design student is putting the finishing touches on her PowerPoint presentation for her speech. She is carefully analyz
elixir [45]

Answer:

Balance

Explanation:

Maintaining balance entails making sure things are in the right place, in the right proportion and maintaining a stable look and stand.

Maintaining a balance on a power point presentation entails that one considers these; ths one should carefully analyse how the different images go together and ensure that the positioning of elements within the images helps to make the individuals point and is pleasing to view.

This can be tasking but worth every effort put in to achieve such, because it will make your presentation to be easier to explain and better understood.

7 0
3 years ago
Which are resources that a programmer might use? Select all that apply.
Hoochie [10]

Answer:

online help and user forums iam not sure of this amswer maybe

5 0
3 years ago
Read 2 more answers
What is one word for inventiveness uncertainty and futuristic
Leni [432]

Answer:

Experimental

Explanation:

5 0
3 years ago
If the user loads this graphic in a text only browser how will the browser describe it?
charle [14.2K]

Im going to say probably not, it wont be able to describe it but it'll search it up and show what others match the image

8 0
3 years ago
Read 2 more answers
Other questions:
  • You bought a monochrome laser printer two years ago. The printer has gradually stopped feeding paper. Which printer component sh
    14·1 answer
  • Which numbering system is used for some network addresses, to describe colors
    6·1 answer
  • What are the five types of alignment in Word?
    12·2 answers
  • In Access, it is possible to have _______________ fields, that is, fields that can contain more than one value.
    9·1 answer
  • Write a program that accepts the lengths of three sides of a triangle as an input from the user: A, B, C
    13·1 answer
  • What do you understand by the term polysome?​
    14·1 answer
  • What caused accident? into passive voice​
    13·1 answer
  • Need answer ASAP
    14·1 answer
  • Explain drawing and painting package.​
    12·1 answer
  • Algorithm to eat orange<br><br>​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!