Segmentation Faults Recall what causes segmentation fault and bus errors from lecture. Common cause is an invalid pointer or address that is being dereferenced by the C program. Use the program average.c from the assignment page for this exercise. The program is intended to find the average of all the numbers inputted by the user. Currently, it has a bus error if the input exceeds one number. Load average.c into gdb with all the appropriate information and run it. Gdb will trap on the segmentation fault and give you back the prompt. First find where the program execution ended by using backtrace (bt as shortcut) which will print out a stack trace. Find the exact line that caused the segmentation fault.
Q13. What line caused the segmentation fault?
Q14. How do you fix the line so it works properly?
You can recompile the code and run the program again. The program now reads all the input values but the average calculated is still incorrect. Use gdb to fix the program by looking at the output of read_values. To do this, either set a breakpoint using the line number or set a breakpoint in the read_values function. Then continue executing to the end of the function and view the values being returned. (To run until the end of the current function, use the finish command).
Q15. What is the bug? How do you fix it?
//average.c
#include
/*
Read a set of values from the user.
Store the sum in the sum variable and return the number of values
read.
*/
int read_values(double sum) {
int values=0,input=0;
sum = 0;
printf("Enter input values (enter 0 to finish):\n");
scanf("%d",&input);
while(input != 0) {
values++;
sum += input;
scanf("%d",input);
}
return values;
}
int main() {
double sum=0;
int values;
values = read_values(sum);
printf("Average: %g\n",sum/values);
return 0;
}

Answers

Answer 1

Answer:

See Explanation

Explanation:

Q13. Line that caused the segmentation fault?

The segmentation fault was caused by line 15 i.e. scanf("%d",input);

Q14. How the line was fixed?

The reason for the segmentation fault is that the instruction to get input from the user into the integer variable "input" was not done correctly.

The correction to this is to modify scanf("d",input) to scanf("%d",input);

Q15. The bug?

The bug is that the method needs to return two value; the sum of the inputted numbers and the count of the inputted numbers.

However. it only returns the count of the inputted number.

So, the average is calculated as: 0/count, which will always be 0

How it was fixed?

First, change the method definition to: void and also include an array as one of its parameters.

void read_values(double sum, double arr []) {

Next:

assign sum to arr[0] and values to arr[1]

In the main method:

Declare an array variable: double arr [2];

Call the read_values function using: read_values(sum,arr);

Get the sum and values using:

sum = arr[0];

values = arr[1];

Lastly, calculate and print average:

printf("Average: %g\n",sum/values);

See attachment for complete modified program


Related Questions

2. You are developing a new application that optimizes the processing of a warehouse’s operations. When the products arrive, they are stored on warehouse racks. To minimize the time it takes to retrieve an item, the items that arrive last are the first to go out. You need to represent the items that arrive and leave the warehouse in a data structure. Which data structure should you use to represent this situation?
a) array
b) linked list
c) stack
d) queue

Answers

Answer:

Option d) is correct

Explanation:

To optimize the processing of a warehouse’s operations, products are stored on warehouse racks when they arrive. The items that arrive last are the first to go out to minimize the time it takes to retrieve an item. The items that arrive need to be represented and the warehouse should be left in a data structure. The data structure which should you use to represent this situation is a queue.

Option d) is correct

When using the Mirror command you can delete the source object as the last step of the command. True or false

Answers

Answer:

The anwser is true it is true.

Use the drop-down menus to explain what happens when a manager assigns a task in Outlook.
1. Managers can assign tasks to other users within_______ .
2. Once the task is assigned, Outlook__________ the assignment to that user.
3. The user must_______ the task to have it placed in their_________ .

Answers

Answer:

1. an organization

2. emails

3. accept

4. to-do list

Explanation: edge

Answer:Use the drop-down menus to complete statements about assigning tasks in Outlook.

A Task Request form is an interactive way to assign tasks to

✔ Outlook users

and report updates on the status of an assigned task.

An assigned task sends

✔ an email

request for the user to accept or decline and sends

✔ an automated response message

to the assigner.

Explanation:

Write a program which will enter information relating to a speeding violation and then compute the amount of the speeding ticket. The program will need to enter the posted speed limit, actual speed the car was going, and whether or not the car was in a school zone and the date of the violation. Additionally, you will collect information about the driver (see output for specifics). The way speeding tickets are computed differs from city to city. For this assignment, we will use these rules, which need to be applied in this order:

Answers

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 float speedlimit, actualspeed;

 String ddate;

 int schoolzone;

 System.out.print("Speed Limit: ");

 speedlimit = input.nextFloat();

 System.out.print("Actual Speed: ");

 actualspeed = input.nextFloat();

 System.out.print("Date: ");

 ddate = input.nextLine();

 System.out.print("School Zone (1-Yes): ");

 schoolzone = input.nextInt();

 float ticket = 75;

 ticket += 6 * (actualspeed - speedlimit);

 

 if(actualspeed - speedlimit > 30){

     ticket+=160;

 }

 if(schoolzone == 1){

     ticket*=2;

 }  

 System.out.print("Date: "+ddate);

 System.out.print("Speed Limit: "+speedlimit);

 System.out.print("Actual Speed: "+actualspeed);

 System.out.print("Ticket: "+ticket);

}

}

Explanation:

See attachment for complete program requirements

This declares speedlimit and actualspeed as floats

float speedlimit, actualspeed;

This declares ddate as string

 String ddate;

This declares schoolzone as integer

 int schoolzone;

This prompts the user for speed limit

 System.out.print("Speed Limit: ");

This gets the speed limit

 speedlimit = input.nextFloat();

This prompts the user for actual speed

 System.out.print("Actual Speed: ");

This gets the actual speed

 actualspeed = input.nextFloat();

This prompts the user for date

 System.out.print("Date: ");

This gets the date

 ddate = input.nextLine();

This prompts the user for school zone (1 means Yes, other inputs means No)

 System.out.print("School Zone (1-Yes): ");

This gets the input for schoolzone

schoolzone = input.nextInt();

This initializes ticket to $75

 float ticket = 75;

This calculates the additional cost based on difference between speed limits and the actual speed

 ticket += 6 * (actualspeed - speedlimit);

If the difference between the speeds is greater than 30, this adds 160 to the ticket  

 if(actualspeed - speedlimit > 30){

     ticket+=160;

 }

If it is in a school zone, this doubles the ticket

 if(schoolzone == 1){

     ticket*=2;

 }  

The following print the ticket information

 System.out.print("Date: "+ddate);

 System.out.print("Speed Limit: "+speedlimit);

 System.out.print("Actual Speed: "+actualspeed);

 System.out.print("Ticket: "+ticket);

Write a java program for the following
A student will not be allowed to sit in exam if his/her attendance is less than 75% .
Take the following input from user
Number of classes held
Number of classes attended
And print
Percentage of class attended
Is student allowed to sit in exam or not .

Answers

Answer:

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 

 Scanner input = new Scanner(System.in);

 

 int classesHeld, classesAttended;

 double percentage;

 

 System.out.print("Enter number of classes held: ");

 classesHeld = input.nextInt();

 

 System.out.print("Enter number of classes attended: ");

 classesAttended = input.nextInt();

 

 percentage = (double) classesAttended / classesHeld;

 

 if(percentage < 0.75)

     System.out.println("You are not allowed to sit in exam");

 else

     System.out.println("You are allowed to sit in exam");

}

}

Explanation:

Import the Scanner to be able to get input from the user

Create a Scanner object to get input

Declare the variables

Ask the user to enter classesHeld and classesAttended

Calculate the percentage, divide the classesAttended by classesHeld. You also need to cast the one of the variable to double. Otherwise, the result would be an int

Check the percentage. If it is smaller than 0.75 (75% equals 0.75), print that the student is not allowed. Otherwise, print that the student is allowed

What would a bar graph best be used for? State why and give 2-3 examples of things you could demonstrate with a bar graph.

Answers

Answer:

Reasons what bar graph is used for.

Explanation:

Bars are shown to compare and contrast data in a bar graph. For example, a data was collected through survey of average rainfall. It represents many unique categories by having many different groups. Those groups are plotted on the x-axis and on the y-axis, the measurements are plotted, like inches.

Hope this helps, thank you !!

Create a flowchart that assigns a counselor to a student.
You need to ask a student for the first letter of his/her last name. Assign a counselor based on the following criteria:
A through M are assigned to Ms. Jones
N through Z are assigned to Mr. Sanchez

Answers

Please Help! Unit 6: Lesson 1 - Coding Activity 2
Instructions: Hemachandra numbers (more commonly known as Fibonacci numbers) are found by starting with two numbers then finding the next number by adding the previous two numbers together. The most common starting numbers are 0 and 1 giving the numbers 0, 1, 1, 2, 3, 5...
The main method from this class contains code which is intended to fill an array of length 10 with these Hemachandra numbers, then print the value of the number in the array at the index entered by the user. For example if the user inputs 3 then the program should output 2, while if the user inputs 6 then the program should output 8. Debug this code so it works as intended.

The Code Given:

import java.util.Scanner;

public class U6_L1_Activity_Two{
public static void main(String[] args){
int[h] = new int[10];
0 = h[0];
1 = h[1];
h[2] = h[0] + h[1];
h[3] = h[1] + h[2];
h[4] = h[2] + h[3];
h[5] = h[3] + h[4];
h[6] = h[4] + h[5];
h[7] = h[5] + h[6];
h[8] = h[6] + h[7]
h[9] = h[7] + h[8];
h[10] = h[8] + h[9];
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
if (i >= 0 && i < 10)
System.out.println(h(i));
}
}

who likes tom holland as spiderman and his web shooter tippets when he swings off buildings in new york city midtown, Forest Hills and he is a superhero and I am his humongous fan of spiderman or peter parker the spider man

Answers

Answer:

YESSSS!!!!

Explanation:

Answer:

ayo no spikar english :u

Wilma is looking for facts about social media for her research project. What fact should she use for her project?

1: Communicating with social media is hard
2: Social media is a great way to communicate.
3: Social media is fun and easy to use.
4:The minimum age for some social media sites is 13.

Answers

the fact she should use for her project is number 4 because that’s the only fact, the rest are opinions!

Which statements about editing an existing Contact in Outlook are true? Check all that apply.

Double-click a contact to open the editing page.
Right-click a contact and click Edit to open the editing page.
Click the Edit link in the Contact Information page to open the editing page.
Contacts can be edited in the body of an email message.
Existing fields can be edited for a Contact in the editing page.
New fields can be added for a Contact on the editing page.

Answers

Answer:

Double-click a contact to open the editing page.

Right-click a contact and click Edit to open the editing page.

Click the Edit link in the Contact Information page to open the editing page.

Existing fields can be edited for a Contact in the editing page.

New fields can be added for a Contact on the editing page.

Explanation:

just did it

The following statements should be considered for editing into an existing contact in Outlook:

Double click the contact in order to open the editing page.Right-click the contact & click on edit to open the editing page.Click on the edit link in the page of contact information for editing the page.The fields that are existed could be altered for a contact in an editing page.The new fields for the contact on the editing page could be added.

The following information should be relevant:

The Contact & editing page is important.Contacts can't be added to the body of the email message.

Therefore we can conclude the above statements should be considered for altering an existing contact in outlook.

Learn more about the outlook here: brainly.com/question/20494929

Define a function roll() that takes no arguments, and returns a random integer from 1 to 6. Before proceeding further, we recommend you write a short main method to test it out and make sure it gives you the right values. Comment this main out after you are satisfied that roll() works.

Answers

Answer:

Follows are the code to this question:

#include <iostream>//defining a header file

using namespace std;

int roll()//defining a method roll

{

return 1+(rand() %5);//use return keyword that uses a rand method

}

int main()//defining main method

{

cout<<roll();//calling roll method that print is value

return 0;

}

Output:

4

Explanation:

In this code,  the "roll" method is defined, that uses the rand method with the return keyword, that returns the value between 1 to 6, and in the next step, the main method is declared, that uses the print method to calls the roll method.

A marketing plan includes a number of factors, including the marketing mix.
What is the marketing mix?
A. The variables of product, price, place, and promotion
B. Using names and symbols to ideny the company's products
C. How the company intends for customers to view its product
relative to the competition
D. A plan for spending money
SUBMIT

Answers

A marketing plan includes a number of factors, including the marketing mix.
What is the marketing mix?
A. The variables of product, price, place, and promotion

Write a program called clump that accepts an ArrayList of strings as a parameter and replaces each pair of strings with a single string that consists of the two original strings in parentheses separated by a space. If the list is of odd length, the final element is unchanged. For example, suppose that a list contains

Answers

Answer:

In Java:

public static void clump(ArrayList<String> MyList) {  

   for(int i = 0; i<MyList.size()-1;i++){

       String newStr = "(" + MyList.get(i) + " "+ MyList.get(i + 1) + ")";

  MyList.set(i, newStr);

  MyList.remove(i + 1);

   }

       System.out.println("Updated ArrayList: " + MyList);

 }

Explanation:

First, we define the method

public static void clump(ArrayList<String> MyList) {  

Next, we iterate through the ArrayList

   for(int i = 0; i<MyList.size()-1;i++){

This clumps/merges every other ArrayList element

       String newArr = "(" + MyList.get(i) + " "+ MyList.get(i + 1) + ")";

This updates the elements of the ArrayList

  MyList.set(i, newArr);

This removes ArrayList elements at odd indices (e.g. 1,3...)

  MyList.remove(i + 1);

   }

This prints the updated List

       System.out.println("Updated ArrayList: " + MyList);

 }

when food material are preserved at a temperature just above freezing the temperature process is called​

Answers

It’s freezing. The process is called freezing

What’s the difference packet switching and message switching??

Answers

Im not sure but the person above is right x :)))


Explanation dudjdb

Changing the color of the text in your document is an example of

Answers

Answer:

???????????uhhh text change..?

Explanation:

Answer:

being creative

Explanation:

cause y not?

Which of the following is the best way to keep up with trends in your industry?
Read the newspaper
Watch the news
Conduct scholarly research
Use social media

Answers

Answer:

Use social media

Explanation:

Social media has significantly helped to bridge gaps in the communication as end users are able to send and receive messages in real-time without any form of delay. Also, social media platforms facilitate the connection of friends, families, co-workers and brands with one another by sharing memories, innovations, new technologies, knowledge and ideas without being physically present in the same location through the use of social network services such as Face-book, Insta-gram, Twitter, LinkedIn, Zoom, Sk-ype, Hangout, You-Tube, etc.

Hence, the best way to keep up with trends in your industry is to through the use of social media because you get to see and learn from trending ideas, methods of production, technologies, and innovations that are being posted from time to time.

Write VHDL code for the circuit corresponding to an 8-bit Carry Lookahead Adder (CLA) using structural VHDL (port maps). (To be completed before your lab session.)

Answers

Answer:

perdo si la pusiera es español te ayudo pero no esta en español

I need help I would really appreciate it

Answers

Answer:

Checks if it is a multiple of 3 and 5

Explanation:

Its an if statement using modulus division to check for a remainder. It checks if a number is a multiple of 3 AND 5. (&& and & both mean and in Java).

If the remainder of both is 0 then that means the mystery number is a multiple of both 3 and 5.

Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A for loop should then iterate once for each floor. In each iteration of the for loop, the program should ask the user for the number of rooms of the floor and how many of them are occupied. After all of the iterations are complete the program should display how many rooms the hotel has, how many of them are occupied, and the percentage of rooms that are occupied.

Answers

Answer:

In Python:

floor = int(input("Number of floors: "))

totalrooms = 0

totaloccupied = 0

for i in range(floor):

   rooms = int(input("Rooms in floor "+str(i+1)+": "))

   occupied = int(input("Occupied Rooms in floor "+str(i+1)+": "))

   totalrooms = totalrooms + rooms

   totaloccupied = totaloccupied + occupied

   

print("Total Rooms: "+str(totalrooms))

print("Total Occupied: "+str(totaloccupied))

print("Percentage Occupied: "+str(round(100*totaloccupied/totalrooms,2))+"%")

Explanation:

This line prompts the user for number of rooms

floor = int(input("Number of floors: "))

This line initializes totalrooms to 0

totalrooms = 0

This line initializes totaloccupied to 0

totaloccupied = 0

This iterates through the floors

for i in range(floor):

This gets the number of rooms in each floor

   rooms = int(input("Rooms in floor "+str(i+1)+": "))

This gets the number of occupied rooms in each floor

   occupied = int(input("Occupied Rooms in floor "+str(i+1)+": "))

This calculates the total number of rooms

   totalrooms = totalrooms + rooms

This calculates the total number of occupied rooms

   totaloccupied = totaloccupied + occupied

   

This prints the total number of rooms

print("Total Rooms: "+str(totalrooms))

This prints the total number of occupied rooms

print("Total Occupied: "+str(totaloccupied))

This prints the percentage of occupied rooms to 2 decimal places

print("Percentage Occupied: "+str(round(100*totaloccupied/totalrooms,2))+"%")

What are the WORST computer malware in your opinion it can be worms backdoors and trojans I just want a input, nothing right or wrong

Answers

Answer:

I think probably mydoom

Explanation:

as it estimated 38 billion dollars in damage, also this malware is technically a worm

State whether the data described below are discrete or​ continuous, and explain why. The durations of movies in seconds

Answers

Answer:

the data are continuous because the data can take any value in an interval.

What should Stephan do to improve his study environment? Check all that apply. remove distracting technology have easy access to his study resources ask his parents to leave the room leave some food and drink for snacks while studying allow his dad to stay only if he is helping with studying remove all food and drink from the room​

Answers

Answer:

I. Remove distracting technology.

II. Have easy access to his study resources.

III. Allow his dad to stay only if he is helping with studying.

Explanation:

A study environment can be defined as a place set aside for reading and studying of educational materials.

In order to facilitate or enhance the ability of an individual (student) to learn and assimilate information quickly, it is very important to ensure that the study environment is devoid of any form of distraction and contains the necessary study materials (resources).

Hence, to improve his study environment, Stephan should do the following;

I. Remove distracting technology such as television, radio, games, etc.

II. Have easy access to his study resources. Stephan shouldn't keep his study materials far away from his study area.

III. Allow his dad to stay only if he is helping with studying.

Answer:the person above it right

Explanation:

I need help for my computer science class I would appreciate it

Answers

Answer:

21

Explanation:

a = 7

b = 7

c = 2

7 is greater than or equal to 7 , so it will return 7 + 7 *2 which is 21

Which of these is NOT a mathematical operator used in Python?

A. !
B. /
C. %
D. *

Answers

the answer is A. i wouldn’t seen any mathematical question that has to do with “!”

why was the 80s bad for Disney i know one example but ill tell you after you answer

Answers

Answer:

The dark stories behind it? i dont  know lol

Compression algorithms vary in how much they can reduce the size of a document.
Which of the following would likely be the hardest to compress?
Choose 1 answer:

A. The Declaration of Independence

B. The lyrics to all of the songs by The Beatles

C. A document of randomly generated letters

D. A book of nursery rhymes for children

Answers

b the lyrics to all of the songs by the beatles !

The statement that represents the thing that would likely be the hardest to compress is a document of randomly generated letters. Thus, the most valid option for this question is C.

What is an Algorithm?

An algorithm may be characterized as a type of methodology that is significantly utilized for solving a problem or performing a computation with respect to any numerical problems.

According to the context of this question, an algorithm is a set of instructions that allows a user to perform solutions with respect to several numerical and other program-related queries. It can significantly act as an accurate list of instructions that conduct particular actions step by step in either hardware- or software-based routines.

Therefore, the statement that represents the thing that would likely be the hardest to compress is a document of randomly generated letters. Thus, the most valid option for this question is C.

To learn more about Algorithms, refer to the link:

https://brainly.com/question/24953880

#SPJ3

Which heading size fits for the word headings​

Answers

Answer:

Explanation:

h1 i think

The ABC box company makes square puzzle cubes that measure 4 inches along each edge. They shipped the cubes in a box 8 in x 12 in x 16 in. How many cubes can they ship in the box?

Answers

Answer: They can ship 32 puzzle cubes in the box.

Explanation: So the volume of each puzzle cubes = side³

=(4)³ cubic inches.

Then the volume of the box is= (8×12×16) cubic inches.

(8×12×16)/4^3= 32

A broadband connection is defined as one that has speeds less than 256,000 bps.
Question 25 options:
True
False

Answers

Answer:

A typical broadband connection offers an Internet speed of 50 megabits per second (Mbps), or 50 million bps.

Explanation:

I think I got it right, plz tell me if im wrong

Other Questions
A rectangular pool is filled with 18.75 cubic meters of water. If the pool is 5 meters long and 2.5 meters wide, what is the depth of the pool? Equivalent fraction of 4/5 This description allows readers to visualizeRead the passage from Part 1 of "To Build a Fire."The Yukon lay a mile wide and hidden under three feet ofice. On top of this ice were as many feet of snow. It wasall pure white, rolling in gentle undulations where the icejams of the freeze-up had formed. North and south, asfar as his eye could see, it was unbroken white, save fora dark hairline that curved and twisted from around thespruce-covered island to the south...O the snow falling from the sky.O the water churning beneath the ice.O the frozen landscape surrounding the trail.O the varied and challenging terrain of the trail. who was Garrett Morgan A 6.00 nC is 2.00 m from a 3.00 nC charge. Find the magnitude of the electric field at a point midway betweenthe two charges? Which way does the electric field point, towards the positive or the negative charge? A rectangle with an area of 47m is dilated by a factor of 7. What is the area of the dilated rectangle? Enter your answer in the box. Do not leave your answer as a fraction. ?m Is pi + 10 a rational number? Answer this chemistry question below Pls help me pls will mark brainliest See picture above and solve surface area Muslim, Latin Christian and Jewish scholars ________________ books of medical and scientific knowledge from Arabic into __________PLSSSSS TELLL MEEE Which sentence uses the most precise language?A.The man honked his horn.B.The car was going fast.C.The red Mustang zipped past the finish line.D.A car uses four wheels and an engine to transport people. Help! Whoever answers first will get brainliest. What is the area of the square on the hypotenuse of the right triangle?A. 5 square unitsC. 16 square unitsB. 9 square unitsD. 25 square units What is always true about a line that slants downward from left to right?Select all that apply.A) The slope of the line is negative.B) As the value of one variable increases, the value of the other variable decreases.C) The slope of the line is a fraction.D) The graph of the line has extremely small values. On Saturday, Mark sold 2 7/8 gallons of lemonade.On the same day, Regan sold 2/3 as much lemonade as Mark.How much lemonade, in gallons, did Regan sell? Which fraction and decimal forms match the long division problem? Negative feedback: If blood pressure is high, the blood vessels should A. dilate (open up more) B. constrict (get tighter) Which excerpt from "How I Learned English" uses first-person point of view to peek into the speaker's mind? X^2- 2x - 54 = 0I need the answer for this please