Write C++ program Question-2: A pyramids are discovered, each has a triangular base with equal sides. An n meters high pyramid is constructed by formingn layers of triangles using Im' cubical stenes. Then layers are stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters base, until the top level which has only I stone. You are asked to calculate the number of stones needed to build a pyramid with the height n. WAIT! We just discovered that some pyramids have a secret room inside. This room is also of the same shape and structure as the pyramid with m layers of stones removed. In order for the room to be secret, m

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ program

Without using vector

Write C++ program
Question-2:
A pyramids are discovered, each has a triangular base with equal sides. An n meters high
pyramid is constructed by forming n layers of triangles using Im' cubical stones. Then layers are
stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters
base, until the top level which has only I stone. You are asked to calculate the number of stones
needed to builda pyramid with the height n.
WAIT! We just discovered that some pyramids have a secret room inside. This room is also of
the same shape and structure as the pyramid with m layers of stones removed. In order for the
room to be secret, m<n-2.
Figure L. (a) 6 layers of stones, and (b)6meters high pyramid.
Example
The total number of stones needed to build a 6 meters high pyramid is
-(1+2+3+4+5+6)*(1+2+3+4+5)-(1+2+3+4)+(1+2+3)+ (1+2)+ 1
-21+15 10+6+3+1-56.
If this pyramid has a 2 meters high secret room, then the total mumber of stones neoded is 56-4
52.
Input
You have to read data from input file named, "input.txt". Each input has twe integers, the finst
represents the pyramid height n, and second represents the secret room height m Input is
terminated by a sequence having n 0, m-0which should not be processol
Isas2000000000, 0 Sms -2
Output
You have to write output to the output file named, "output.txt". For each sequence, you are to
output one line, containing the number of stones needed
Input.tst
Output.tst
56
55
52
36
171699
100 1
Transcribed Image Text:Write C++ program Question-2: A pyramids are discovered, each has a triangular base with equal sides. An n meters high pyramid is constructed by forming n layers of triangles using Im' cubical stones. Then layers are stacked on top of each other. The first layer is the triangle with n meters base, on top, n-1 meters base, until the top level which has only I stone. You are asked to calculate the number of stones needed to builda pyramid with the height n. WAIT! We just discovered that some pyramids have a secret room inside. This room is also of the same shape and structure as the pyramid with m layers of stones removed. In order for the room to be secret, m<n-2. Figure L. (a) 6 layers of stones, and (b)6meters high pyramid. Example The total number of stones needed to build a 6 meters high pyramid is -(1+2+3+4+5+6)*(1+2+3+4+5)-(1+2+3+4)+(1+2+3)+ (1+2)+ 1 -21+15 10+6+3+1-56. If this pyramid has a 2 meters high secret room, then the total mumber of stones neoded is 56-4 52. Input You have to read data from input file named, "input.txt". Each input has twe integers, the finst represents the pyramid height n, and second represents the secret room height m Input is terminated by a sequence having n 0, m-0which should not be processol Isas2000000000, 0 Sms -2 Output You have to write output to the output file named, "output.txt". For each sequence, you are to output one line, containing the number of stones needed Input.tst Output.tst 56 55 52 36 171699 100 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education