The text that is heavier or darker than other text in a document is considered Bold.
Hope this helped!~
Answer:
Output explanation to the given code can be defined as follows:
Explanation:
In A the output is 0
, It will return fork value of the child process that is 0. so, 0 is printed during child process.
In B the output is 2650
, in which the getpid() method returns the child process id value that is 2650.
In C the output is 140, As it is declared in key, all process have their own "value" copies. 20 are inserted during childhood, so 140 are written.
In D the output is 2650, its fork() method returns the child ID to the parent process. so the value 2650 is printed.
In E the output is 2600, Its getpid() method will returns parent process id that is equal to 2600.
In F the output is 120 Since the value is declared in primary, all process so their own "value" copies. 120 will be printed during process.
Answer:
The program to this question can be described as follows:
Program:
#include <iostream> //defining header file
using namespace std;
int main() //defining main method
{
int x; //defining integer variable
for(x=0;x<=100;x++) //defining loop to count value from 0 to 100
{
if(x%7==0) //check value is divisable by 7
{
cout<<x<<endl; //print value
}
}
return 0;
}
Output:
please find the attachment.
Explanation:
In the above code, an integer variable x is declared, which is used in the for loop, in this loop variable "x" starts from 0 and ends when the value of x is less than and equal to 100.
- Inside the loop an, if block is used that defines a condition that is (i%7==0), it will check, that the value is divided by 7.
- In this loop, a print method is used, that prints its values.
Answer:
Option 1: May crash at runtime because it can input more elements than the array can hold
Explanation:
Given the code as follows:
- int[] a = {1, 3, 7, 0, 0, 0};
- int size = 3, capacity = 6;
- int value = cin.nextInt();
- while (value > 0)
- {
- a[size] = value;
- size++;
- value = cin.nextInt();
- }
From the code above, we know the <em>a</em> is an array with six elements (Line 1). Since the array has been initialized with six elements, the capacity of the array cannot be altered in later stage.
However, a while loop is created to keep prompting for user input an integer and overwrite the value in the array started from index 3 (Line 4- 9). In every round of loop, the index is incremented by 1 (Line 7). If the user input for variable <em>value</em> is always above zero, the while loop will persist. This may reach a point where the index value is out of bound and crash the program. Please note the maximum index value for the array is supposedly be 5.
Answer:
Here is the program for the given question
Explanation:
class StringSet
{
ArrayList<String> arraylist; //a reference variable of ArrayList of generic type String
//A no argument constructor.
public StringSet()
{
arraylist=new ArrayList<String>(); //instantiating the ArrayList object
}
//A mutator that adds a String newStr to the StringSet object.
void add(String newStr)
{
arraylist.add(newStr); // add(String) method to add string to the arraylist
}
//An accessor that returns the number of String objects that have been added to this StringSet object.
int size()
{
return arraylist.size(); // size() method which gives the number of elements in the list
}
//An accessor that returns the total number of characters in all of the Strings that have been added to this StringSet object.
int numChars()
{
int sum = 0;
for(String str:arraylist) //for-each loop; can be read as for each string in arraylist
{
sum+=str.length();
}
return sum;
}
//An accessor that returns the number of Strings in the StringSet object that have exactly len characters.
int countStrings(int len)
{
int count = 0;
for(String str:arraylist)
{
if(str.length() == len)
count++;
}
return count;
}
}