The following program contains five different errors that would prevent it from compiling or result in undefined behavior. Identify them by line number, explain briefly the error, and write a fix for it in the space provided. Each properly identified and fixed error is worth three marks. Assume that this code, once corrected, will compile using the GNU g++ compiler on matrix.
The following program contains five different errors that would prevent it from compiling or result in undefined behavior. Identify them by line number, explain briefly the error, and write a fix for it in the space provided. Each properly identified and fixed error is worth three marks. Assume that this code, once corrected, will compile using the GNU g++ compiler on matrix.
C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter10: Pointers
Section10.2: Array Names As Pointers
Problem 2E
Related questions
Question
The following program contains five different errors that would prevent it from compiling or result in undefined behavior. Identify them by line number, explain briefly the error, and write a fix for it in the space provided. Each properly identified and fixed error is worth three marks. Assume that this code, once corrected, will compile using the GNU g++ compiler on matrix.
- #include <iostream>
- using namespace std;
- class WEB222 {
- int *ids;
- int size;
- public:
- WEB222(const int *ids_, int n) {
- ids = new int[n];
- ids = ids_;
- size = n;
- }
- ~WEB222(int n) {
- cout << "deleting all " << n << " ids." << endl;
- delete[] ids;
- }
- void display(){
- for(int i = 0; i < size; i++)
- cout << "id: " << ids[size] << endl;
- }
21.};
- void prn(const WEB222& spp){
- spp.display();
- }
- int main() {
- int ids[3] = {23135, 52134, 67112};
- WEB222 sjj(ids, 3), sbb;
- prn(sjj);
- sbb->display();
- return 0;
- }
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images

Knowledge Booster
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.Recommended textbooks for you

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning

C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr

EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT

C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage

Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning

Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,