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
velikii [3]
3 years ago
10

You are provided with the following program poem.cpp. All is good, and the memory is allocated dynamically, but it crashes your

computer, because it runs out of memory really quickly:
#include
using namespace std;

string * createAPoemDynamically() {
string *p = new string;
*p = "Roses are red, violets are blue";
return p;
}

int main() {
while(true) {
string *p;
p = createAPoemDynamically();

// assume that the poem p is not needed at this point

}
}
Fix this program poem.cpp. It should still keep creating poems, but all dynamically allocated memory should get deleted when it is not needed.
Computers and Technology
1 answer:
Maslowich3 years ago
8 0

Answer:

See explaination

Explanation:

#include <iostream>

using namespace std;

string * createAPoemDynamically()

{

string *p = new string;

*p = "Roses are red, violets are blue";

return p;

}

int main() {

while(true) {

string *p;

p = createAPoemDynamically();

if (!p)

{

cout << "Memory allocation failed\n";

}

cout<<*p<<"\n";

// assume that the poem p is not needed at this point

//delete allocated memory

delete p;

}

}

You might be interested in
The collections framework algorithms are __________, i.e., each of these algorithms can operate on objects that implement specif
Ad libitum [116K]
<h2><em>C.) Polymorphic.</em></h2><h2><em></em></h2>

Just trust a bro, its correct.

4 0
3 years ago
Read 2 more answers
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
svlad2 [7]

Answer:

The program in Python is as follows:

currentPrice = int(input("Current: "))

lastMonth = int(input("Last Month: "))

print("The house is $",currentPrice)

print("The change is $",(currentPrice-lastMonth),"since last month")

print("The estimated monthly mortgage is $",(currentPrice * 0.051) / 12)

Explanation:

Get input for current price

currentPrice = int(input("Current: "))

Get input for last month price

lastMonth = int(input("Last Month: "))

Print current price

print("The house is $",currentPrice)

Print change since last month

print("The change is $",(currentPrice-lastMonth),"since last month")

Print mortgage

print("The estimated monthly mortgage is $",(currentPrice * 0.051) / 12)

6 0
3 years ago
Explain at least 5 parts a a computer.
Stels [109]

Answer: There are many parts of a computer, but there are basic ones and major ones.

Explanation: Computers may look very different, but the components installed are standard. The major difference among most machines is the brand of hardware installed. The hardware components—video card, processor, memory, motherboard and hard drive—are the same for all computer systems. While, these are the major ones: Motherboard.

Processor/CPU.

Power Supply.

Hard Drive.

PCI-Express Cards.

Graphics Cards.

RAM/Memory.

6 0
3 years ago
If you were to create a new app for a smartphone or tablet that does not already exist, what would you create?
omeli [17]
A app that fry’s your Phone or Tablet.
4 0
3 years ago
What is the advantage of using plenum cable for twisted-pair cable?
adell [148]

The advantage of using plenum cable for twisted- pair cable  is it is "Fire resistant"

<u>Explanation:</u>

Plenum cable is a cable that is used in plenum spaces of buildings. These cables have fire resistance characteristic with low smoke. These cables are self extinguishing, and never re-ignite. They require less space for installation and allows space for air circulation to be used by the HVAC system. Twisted-pair, coaxial, HDMI and DVI variants of cable are manufactured in the plenum version. Plenum cable is mandatory to be fixed in any "air handling" area.

7 0
3 years ago
Other questions:
  • The array index can be any nonnegative integer less than the array size.
    10·1 answer
  • I have six nuts and six bolts. Exactly one nut goes with each bolt. The nuts are all different sizes, but it’s hard to compare t
    12·1 answer
  • In your memo, give three new employees directions for starting the computer and opening a word-processing document.
    9·1 answer
  • Which is the most likely reason film companies expanded so quickly?
    8·1 answer
  • What are the three primary separation of concerns on the client-side of a dynamic web application? (Check all that apply)
    13·1 answer
  • When you are using remote control services and need to enter the ip address of the system you want to control, you should use th
    6·1 answer
  • Hello hello . please help me​
    8·2 answers
  • ​what is the difference between a normal mouse and trackball? What do you think. ​​​​
    7·1 answer
  • SOMEONE PLEASE HELP ME OUT WITH!!!!!
    14·2 answers
  • A layout with boxes that can be used to make text easier to read."
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!