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
zhuklara [117]
3 years ago
5

Why is code tracing important when debugging?

Computers and Technology
1 answer:
larisa [96]3 years ago
7 0

It helps reveal the flow of execution of your program, including results of in-between evaluations. In other words, you can see what your program is doing, and why it takes the decisions it is taking.

If something unexpected happens, the trace will show you the sequence of events that lead to it.

You might be interested in
Type (dog, cat, budgie, lizard, horse, etc.) Create a class that keeps track of the attributes above for pet records at the anim
Alenkinab [10]

Answer:

If you did the exercise with two Dog objects, it was a bit boring, right? After all, we have nothing to separate the dogs from each other and no way of knowing, without looking at the source code, which dog produced which bark.

In the previous article, I mentioned that when you create objects, you call a special method called a constructor. The constructor looks like the class name written as a method. For example, for a Dog class, the constructor would be called Dog().

The special thing about constructors is that they are the path to any new object, so they are a great place to call code that initializes an object with default values. Further, the return value from a constructor method is always an object of the class itself, which is why we can assign the return value of the constructor to a variable of the type of class we create.

However, so far, we have not actually created a constructor at all, so how come we can still call that method?

In many languages, C# included, the language gives you a free and empty constructor without you having to do anything. It is implied that you want a constructor; otherwise there would be no way of using the class for anything, so the languages just assume that you have written one.

This invisible and free constructor is called the default constructor, and, in our example, it will look like this:

public Dog(){ }

Notice that this syntax is very similar to the Speak() method we created earlier, except that we do not explicitly return a value nor do we even declare the return type of the method. As I mentioned earlier, a constructor always returns an instance of the class to which it belongs.

In this case, that is the class Dog, and that is why when we write Dog myDog = new Dog(), we can assign the new object to a variable named myDog which is of type Dog.

So let’s add the default constructor to our Dog class. You can either copy the line above or, in Visual Studio, you can use a shortcut: type ctor and hit Tab twice. It should generate the default constructor for you.

The default constructor doesn’t actually give us anything new because it is now explicitly doing what was done implicitly before. However, it is a method, so we can now add content inside the brackets that will execute whenever we call this constructor. And because the constructor runs as the very first thing in an object’s construction, it is a perfect place to add initialization code.

For example, we could set the Name property of our objects to something by adding code such as this:

public Dog()

{

   this.Name = "Snoopy";

}

This example will set the Name property of any new objects to “Snoopy”.

Of course, that’s not very useful because not all dogs are called “Snoopy”, so instead, let us change the method signature of the constructor so that it accepts a parameter.

The parentheses of methods aren’t just there to look pretty; they serve to contain parameters that we can use to pass values to a method. This function applies to all methods, not just constructors, but let’s do it for a constructor first.

Change the default constructor signature to this:

public Dog(string dogName)

This addition allows us to send a string parameter into the constructor, and that when we do, we can refer to that parameter by the name dogName.

Then, add the following line to the method block:

this.Name = dogName;

This line sets this object’s property Name to the parameter we sent into the constructor.

Note that when you change the constructor’s signature, you get a case of the red squigglies in your Program.cs file.When we add our own explicit constructors, C# and .NET will not implicitly create a default constructor for us. In our Program.cs file, we are still creating the Dog objects using the default parameter-less constructor, which now no longer exists.

To fix this problem, we need to add a parameter to our constructor call in Program.cs. We can, for example, update our object construction line as such:

Dog myDog = new Dog(“Snoopy”);

Doing so will remove the red squigglies and allow you to run the code again. If you leave or set your breakpoint after the last code line, you can look at the Locals panel and verify that your object’s Name property has indeed been? Got it?

5 0
2 years ago
Please help <br> what do data communications transmit data through?
I am Lyosha [343]

Answer:There are two methods used to transmit data between digital devices: serial transmission and parallel transmission. Serial data transmission sends data bits one after another over a single channel. Parallel data transmission sends multiple data bits at the same time over multiple channels.

Explanation:

5 0
2 years ago
____ is a limited version of windows that allows you to use your mouse, screen, and keyboard but no other peripheral devices.
Gnoma [55]
'SAFEMODE' <span>is a limited version of windows that allows you to use your mouse, screen, and keyboard but no other peripheral devices.</span>
8 0
2 years ago
.What is Social Media"?
nadezda [96]

Answer:

Social media is an internet-based form of communication. It facilitates the users the sharing of ideas, thoughts and information, and create web content.

There are many forms of social media, like blogs, photo-sharing sites, virtual words, etc.

8 0
2 years ago
If the decimal number 4 is represented in binary as 100, then what is the binary representation of the decimal number 5?
Allisa [31]
5 is one bigger than 4, so it is 101

Note: this doesn't always work for every number.

the binary numbers 1-8 would be: 1, 10, 11, 100, 101, 110, 111, 1000

Can you guess 9?: 1001

10?: 1010

Hope this helps, <span>and May the Force Be With You!
-Jabba


</span>
8 0
3 years ago
Other questions:
  • You can use RWA to demonstrate how to do something special on the web, such as displaying articles found on websites that suppor
    15·1 answer
  • Write a query to show the price reduced by 10% for all products that are tables or entertainment centers with a standard price g
    10·1 answer
  • in a management information system, the quality of information is determined by its usefulness to users, and its usefulness dete
    8·1 answer
  • In presentation software, what is the way that text and pictures are arranged on a page called?
    10·1 answer
  • Which of the following JavaScript expressions is equivalent to the given HTML code? ​ a. Document.getelementbyId("menu1").menu=
    6·1 answer
  • NEED HELP RIGHT NOW!!! Which of the following is the definition of a privacy policy? * 5 points - A legal document that an app o
    6·1 answer
  • this bar is located at the top of your computer school in.Its functions allow you to navigate the web​
    5·2 answers
  • a. Daily Life Magazine wants an analysis of the demographic characteristics of its readers. The marketing department has collect
    13·1 answer
  • What type of formula uses data from multiple worksheets
    6·1 answer
  • What are some ways you can use the Effect Options dialog box to customize animations in a presentation? Check all
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!