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
9.2.8 last names codehs
ZanzabumX [31]

Using the knowledge of computational language in python it is possible to write a code that tries to organize the names in an assorted way and any name can be included.

<h3>Writing code in python:</h3>

<em>names_list = []</em>

<em>for i in range(0, 5):</em>

<em>    names_list.append(input("Name: "))</em>

<em>sorted_last_names = sorted([name.split()[-1] for name in names_list])</em>

<em>print(sorted_last_names)</em>

See moer about python at brainly.com/question/18502436

#SPJ1

8 0
2 years ago
What will happen if storage devices are removed from computer?​
Simora [160]

Answer:

It will reset its data and memory, and you will have to restart from the basics to the advanced stuff. It will also remove the ability to store data to save files.

Explanation:

Hope this helps.

4 0
3 years ago
Read 2 more answers
The sum of the elements of an integer-valued array recursively calculated as follows: The sum of an array of size 0 is 0; Otherw
Ugo [173]
In what language? Most languages have iterator functions like map in JavaScript that will loop through the elements, making this almost a one liner

sum = 0
arr.map( elem => sum += elem )
8 0
3 years ago
If known vulnerabilities in software are entry points for an attacker, why are the software vulnerabilities not corrected before
Evgesh-ka [11]

Answer:

we dont knoqw

Explanation:

7 0
2 years ago
Dir, attrib, cd, and rem are all examples of:
konstantin123 [22]
Dir, attrib, cd, and rem are all examples of DOS Commands. dir command is used to display a list of files and folders contained inside your current folder. Attrib changes or views the attributes of one or more files. CD id for changing directory.  rem<span> command is used to record comments in a script file.</span>
3 0
3 years ago
Read 2 more answers
Other questions:
  • Identify the correct software or hardware applications in the passage below
    10·1 answer
  • The operating system is not directly involved in one of these tasks.Immersive Reader
    12·1 answer
  • On most computers, the default font size in word is ____. 8 11 14 16
    8·2 answers
  • What Intel socket recommends the use of a liquid cooling system?
    9·1 answer
  • An attacker captures an encrypted message. he tries decrypting with every possible key until the decryption process reveals a se
    14·1 answer
  • Which formulas would work to combine cells with first, middle, and last names from columns A through C and row 2 into a new cell
    14·2 answers
  • Ashton assigned a string value to a variable. Which program statement should he use?
    7·1 answer
  • OkkKkkkkkEYEYYEYEYEY BYEYYEYEYEyeeyeyyeEYEy if you know you know
    11·1 answer
  • Match the following internet related terms to their definition
    13·1 answer
  • Rr lyrae stars pulsate, but with shorter periods and lower luminosities than cepheids. true false
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!