Question

Q4 6 Points List 3 things that are wrong with the following code: int *n - new int; // line 1 bool x - false; // line 2 bool

Hi I need help on C++ coding hw Q! thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You.


6 7 8 9 10 11 12 13 14 15 16 int *n = new int; bool x = false; bool *b; int p = n; *b = true; delete n; b = &x; delete bi del

   int *n = new int; //line 1 Error : here there should be number when initialize int . Like int *n = new int[1];
   bool x = false; //line 2
   bool *b; //line 3
   int *p = n; //line 4
   *b = true; //line 5 Error : Here *b assignment is without memory allocation . First b should be initialized
   delete n; //line 6
   b = &x; //line 7
   delete b; //line 8
   delete p; //line 9 Error : pointer p cannot be deleted. p and n are same. And n deleted already, So it will cause error

Add a comment
Know the answer?
Add Answer to:
Hi I need help on C++ coding hw Q! thank you! Q4 6 Points List 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual...

    Hi I got error C2660 : 'valuein' : function does not take 2 parameters in visual studio 2013 this is my code so far #include <cstdlib> #include <list> #include <iostream> using namespace std; struct node {    int data;    node* next; }; void initialize(node*p); void insert(int data,int n); void remove(int b,int pos); bool empty(node*); void length(); bool valuein(int c); int reportvalue(int value); void ptintlist(); int menu(); int main() {    struct node*head=NULL;    char commands;    int value;   ...

  • Hi I have 4 problems below I need done ASAP, if you could upload them one...

    Hi I have 4 problems below I need done ASAP, if you could upload them one by one by order you finish them instead of all at once that would be appreciated, I need this done in basic c++ code, all of the body structure are below I just need codes to be implemented for the codes to give the write outputs, Thank you. Q1. Update the given code 1 to implement the following problem: Create a class animal Set...

  • LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10...

    LANGUAGE C++ I need help with all 3 questions. Thank you in advance Password Generator← 10 10.201.51. eRAD D scheduling山UitPro 6 Fizz Buzz Write a function "void FizzBuzz(int n)" that lists all of the numbers from 1 to n, but replace all numbers divisible by 3 but not divizible by 5 with the word "Fizz", replace all numbers divisible by 5 but not divisible by 3 with the word "Buzz", and replace all numbers divisible by both 3 and 5...

  • Hi I need some help in C programing class and I doing one of the exercise...

    Hi I need some help in C programing class and I doing one of the exercise so that I can get better at coding. Suppose you are asked to design a software that helps an elementary school student learn multiplication and division of one-digit integer numbers. The software allows the student to select the arithmetic operation she or he wishes to study. The student chooses from a menu one of two arithmetic operations: 1) Multiplication and 2) Division (quotient). Based...

  • C++ assignment help! The instructions are below, i included the main driver, i just need help...

    C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...

  • NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------...

    NEED ASAP PLEASE HELP Task: --------------------------------------------------------------------------------------------------------------------------------- Tasks to complete: ---------------------------------------------------------------------------------------------------------------------------------------- given code: ----------------------------------------------------------------------------------------------------------------------------------------------- main.cpp #include <iostream> #include <iomanip> #include "fractionType.h" using namespace std; int main() { fractionType num1(5, 6); fractionType num2; fractionType num3; cout << fixed; cout << showpoint; cout << setprecision(2); cout << "Num1 = " << num1 << endl; cout << "Num2 = " << num2 << endl; cout << "Enter the fraction in the form a / b: "; cin >> num2; cout << endl; cout <<...

  • Hi I need some help on this lab. The world depends on its successfull compilation. /*...

    Hi I need some help on this lab. The world depends on its successfull compilation. /* Lab5.java Arrays, File input and methods Read the comments and insert your code where indicated. Do not add/modify any output statements */ import java.io.*; import java.util.*; public class Lab5 { public static void main (String[] args) throws Exception { final int ARRAY_MAX = 30; // "args" is the list of tokens you put after "java Project3" on command line if (args.length == 0 )...

  • Hi, I need help on my assignment for my discrete structures class. Thank you, and I...

    Hi, I need help on my assignment for my discrete structures class. Thank you, and I will remember to rate your answer! 3. Prove that n! > 2" for n 24 Prove that x, 1 is divisible by x-1 for x # 1. Note: we are doing the induction on n, not x. With the caveat that x is not 1, we want to show that x2 - 1 is divisible by x - 1, x'- 1 is divisible by...

  • Hi I need help with question 3 shown below. Thank you This problem references problem 2,...

    Hi I need help with question 3 shown below. Thank you This problem references problem 2, which I have already completed 3) The p-n junction of problem 2 has a cross sectional area of 103 cm2. Calculate: a) the total depletion zone width, b)n-side depletion zone width, c) p-side depletion zone width, d) total charge on the n side, e) total charge on the p side and f) the peak electric field magnitude. g) Sketch εχ vs. x and the...

  • Hi! I need help with a C++ program In this assignment, you will create some routines...

    Hi! I need help with a C++ program In this assignment, you will create some routines that will later be used in a "Black Jack" program. Your output on this first part will look something like: card's name is QC with a black jack value of 10 Unshuffled Deck AC/1 2C/2 3C/3 4C/4 5C/5 6C/6 7C/7 8C/8 9C/9 TC/10 JC/10 QC/10 KC/10 AD/1 2D/2 3D/3 4D/4 5D/5 6D/6 7D/7 8D/8 9D/9 TD/10 JD/10 QD/10 KD/10 AH/1 2H/2 3H/3 4H/4 5H/5...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT