Answer:
C++ code is explained below
Explanation:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Variables to store inputs
string robot_name = "Nao";
string visitor_name;
int age, first_num, second_num;
// Constant variable initialisation for programmer name
const string programmer_name = "XXXXXXXX";
// Constant variable initialisation for assignment number
const string assignment_num = "123546";
// Constant variable initialisation for due date
const string due_date = "16 August, 2019";
// Displaying robot's name as script
cout << "Hello, welcome to Montgornery College!";
cout << "My name is " << robot_name << " . May I have your name?" << "\n\n";
// Taking visitor's name as input from the visitor
cin >> visitor_name;
// Displaying vistor's name as script
cout << "\n\nNice to have your with us today, " << visitor_name << "! ";
cout << "Let me impress you with a small game.";
cout << "Give me the age of an important person or a pet to you. ";
cout << "Please give me only a number!" << "\n\n";
// Taking human age as input from the visitor
cin >> age;
// Displaying human's age as script
cout << "\n\nYou have entered " << age << ". If this is for a person,";
cout << " the age can be expressed as " << age << " years or ";
// Computing months, days, hours, minutes and seconds from age input
double months = age*12;
double days = months*30;
double hours = days*24;
double minutes = hours*60;
double seconds = minutes*60;
// Computing dogs and fish age from human's age
double dogs_age = 7*age;
double gold_fish_age = 5*age;
// Displaying months, hours, minutes, hours and seconds as script
cout << months << " months or about " << days << " days or";
cout << " about " << fixed << setprecision(0) << hours << " hours or about " << minutes;
cout << " or about " << fixed << setprecision(0) << seconds << " seconds. If this is for a dog.";
// Displaying dogs age and gold fish age as script
cout << " it is " << dogs_age << " years old in human age.";
cout << " If this is for a gold fish, it is " << gold_fish_age;
cout << " years old in human age" << "\n\n";
cout << "Let's play another game, " << visitor_name << "!";
cout << "Give me a whole number." << "\n\n";
// Taking first whole number from the visitor
cin >> first_num;
cout << "\nVery well. Give me another whole number." << "\n\n";
// Taking second whole number from the vistor
cin >> second_num;
// Computing sum and division for displaying in the script
double sum = first_num+second_num;
double division = first_num/second_num;
float floatDivision = (float)first_num/second_num;
// Displaying sum and division script
cout << "\nUsing the operator '+' in C++,";
cout << " the result of " << first_num << " + " << second_num;
cout << " is " << sum << ". Using the operator '/', the result ";
cout << "of " << first_num << " / " << second_num << " is " << division;
cout << "; however, the result of " << first_num << ".0 /" << second_num;
cout << ".0 is about " << floatDivision << "." << "\n\n";
cout << "Do you like the games, " << visitor_name << "?";
cout << " If you do, you can learn more by taking our classes.";
cout << ". If you don't, I am sad, You should talk to our Chairman!" << "\n\n";
// Displaying Programmer Name, Assignment Number and due date to output screen
cout << "Programmer Name : " << programmer_name << endl;
cout << "Assignment Number : " << assignment_num << endl;
cout << "Due Date : " << due_date << endl;
return 0;
}
Write a method called printGrid that accepts two integers representing a number of rows and columns and prints a grid of integers from 1 to (rows * columns) in column major order. For example, the call printGrid(4, 6); should produce the following output: 1 5 9 13 17 212 6 10 14 18 223 7 11 15 19 234 8 12 16 20 24
Answer:
See attached pictures.
Explanation:
See attached picture for code with explanation.
The following program includes fictional sets of the top 10 male and female baby names for the current year. Write a program that creates: A set all_names that contains all of the top 10 male and all of the top 10 female names. A set neutral_names that contains only names found in both male_names and female_names. A set specific_names that contains only gender specific names. Sample output for all_names: {'Michael', 'Henry', 'Jayden', 'Bailey', 'Lucas', 'Chuck', 'Aiden', 'Khloe', 'Elizabeth', 'Maria', 'Veronica', 'Meghan', 'John', 'Samuel', 'Britney', 'Charlie', 'Kim'} NOTE: Because sets are unordered, they are printed using the sorted() function here for comparison
Answer:
Following are the program in the Python Programming Language.
male_names = {'kay', 'Dev', 'Sam', 'Karan', 'Broly', 'Samuel', 'Jayd', 'Lucifer', 'Amenadiel', 'Anmol'}
female_names = {'Kally', 'Megha', 'Lucy', 'Shally', 'Bailey', 'Jayd', 'Anmol', 'Beth', 'Veronica', 'Sam'}
#initialize the union from male_names and female_names
all_names = male_names.union(female_names)
#Initialize the similar names from male_names and female_names
neutral_names = male_names.intersection(female_names)
#initialize the symmetric_difference from male_names and female_names
specific_names = male_names.symmetric_difference(female_names)
#print the results
print(sorted(all_names))
print(sorted(neutral_names))
print(sorted(specific_names))
Output:
['Amenadiel', 'Anmol', 'Bailey', 'Beth', 'Broly', 'Dev', 'Jayd', 'Kally', 'Karan', 'Lucifer', 'Lucy', 'Megha', 'Sam', 'Samuel', 'Shally', 'Veronica', 'kay']
['Anmol', 'Jayd', 'Sam']
['Amenadiel', 'Bailey', 'Beth', 'Broly', 'Dev', 'Kally', 'Karan', 'Lucifer', 'Lucy', 'Megha', 'Samuel', 'Shally', 'Veronica','kay']
Explanation:
The following are the description of the program.
In the above program, firstly we set two list data type variables 'male_names' and 'female_names' and initialize the male and female names in those variables. Then, we set three variables in which we store union, intersection, and symmetric differences and finally print these three variables in a sorted manner.Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds.
Answer:
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// Using fork() creates child process which is identical to parent
int pid = fork();
// Creating the Parent process
if (pid > 0)
sleep(10);
// And then the Child process
else
{
exit(0);
}
return 0;
}
Explanation:
Using a Text editor enter the code in the Answer section and save it as zombie.c. The created process will be able to run for 10 seconds.
Now open the Terminal and type $ cc zombie.c -o zombie to compile the program which is then saved as an executable file.
With a GNU compiler run the following command ./zombie which will give you an output of the parent process and child process to be used testing.
Part A [10 points] Create a class named Case that represents a small bookbag/handbag type object. It should contain: Fields to represent the owner’s name and color of the Case. This class will be extended so use protected as the access modifier. A constructor with 2 parameters – that sets both the owner’s name and the color. Two accessor methods, one for each property. (getOwnerName, getColor) A main method that creates an instance of this class with the owner’s name set to ‘Joy’ and color set to ‘Green’. Add a statement to your main method that prints this object. Run your main method
Answer:
class Case //Case class
{
String owner_name,color; //members to store information name and color
Case(String name,String color) //constrictor with two parameters
{
this.owner_name = name; //members initialization
this.color = color;
}
public String getName() //to get name
{
return owner_name;
}
public String getColor() //to get color
{
return color;
}
public String toString()//override string method
{
return "Case Owner: " + owner_name + ", " + "Color: "+ color;
}
}
class Main //test class
{
public static void main(String args[])
{
String na,color;
Case c = new Case("Joy","Green"); //create instance of class Case and set constructor parameters
na = c.getName();
color = c.getColor();
System.out.println(c);//print statement tp print instance of a class
System.out.println(c.toString()); //print with override toString
}
}
Explanation:
First identify the formula to compute the sales in units at various levels of operating income using the contribution margin approach. (Abbreviations used: Avg. = average, and CM = contribution margin.) ( + ) / = Breakeven sales in units
Answer:
10 stand scooters and 15 chrome scooters
Explanation:
Data:
The margin approach:
(Fixed expenses + Operating income)/ Weighted average CM per unit = Break even sales in units.
Tallying from the tables, the types and quantities that need to be sold will be like this:
Standard scooters = 10
Chrome scooters = 15
For each of the following languages, state with justification whether it isrecognizableor unrecognizable.(a)LHALT≥376={(〈M〉, x) : machine halts on input after 376 or more steps}(b)LLIKES-SOME-EVEN={〈M〉:Maccepts some even number}(c)L
Answer:
See the picture attached
Explanation:
Suppose a process in Host C has a UDP socket with port number 6789. Suppose both Host A and Host B each send a UDP segment to Host C with destination port number 6789. Will both of these segments be directed to the same socket at Host C
Answer:
Yes, both of these segments (A and B) will be directed to the same socket at Host C .
Explanation:
Suppose both Host A and Host B each send a UDP segment to Host C with destination port number 6789, surely , both of these segments will be directed to the same socket at Host C .
Reason being that, the operating system will provide the process with the IP details to distinguish between the individual segments arriving at host C- for each of the segments (A and B) recieved at Host C.
The cybersecurity defense strategy and controls that should be used depend on __________. Select one: a. The source of the threat b. Industry regulations regarding protection of sensitive data c. What needs to be protected and the cost-benefit analysis d. The available IT budget
Answer:
The answer is "Option C"
Explanation:
It is an information warfare-security method, that consists of a set of defense mechanisms for securing sensitive data. It aimed at improving state infrastructure security and stability and provides high-level, top-down, which lays out several new goals and objectives to be met within a certain timeline, and incorrect options can be described as follows:
In option a, These securities can't include threats. Option b, and Option d both are incorrect because It is used in industry but, its part of networking.For loops: Savings account The for loop calculates the amount of money in a savings account after numberYears given an initial balace of savingsBalance and an annual interest rate of 2.5%. Complete the for loop to iterate from 1 to numberYears (inclusive). Function Save Reset MATLAB DocumentationOpens in new tab function savingsBalance = CalculateBalance(numberYears, savingsBalance) % numberYears: Number of years that interest is applied to savings % savingsBalance: Initial savings in dollars interestRate = 0.025; % 2.5 percent annual interest rate % Complete the for loop to iterate from 1 to numberYears (inclusive) for ( ) savingsBalance = savingsBalance + (savingsBalance * interestRate); end end 1 2 3 4 5 6 7 8 9 10 11 12 Code to call your function
Answer:
Desired MATLAB code is explained below
Explanation:
function savingsBalance = CalculateBalance(numberYears, savingsBalance)
% numberYears: Number of years that interest is applied to savings
% savingsBalance: Initial savings in dollars
interestRate = 0.025; % 2.5 percent annual interest rate
% Complete the for loop to iterate from 1 to numberYears (inclusive)
for (i = 1 : numberYears)
savingsBalance = savingsBalance + (savingsBalance * interestRate);
end
end
The completed for loop in MATLAB iterates from 1 to `numberYears`, updating the `savingsBalance` by adding 2.5% interest each year:
```matlab
for year = 1:numberYears
savingsBalance = savingsBalance + (savingsBalance * interestRate);
end
```
To complete the `for` loop in the given MATLAB function to calculate the amount of money in a savings account after a specified number of years, you need to iterate from 1 to `numberYears` (inclusive). Here’s the completed function:
```matlab
function savingsBalance = CalculateBalance(numberYears, savingsBalance)
% numberYears: Number of years that interest is applied to savings
% savingsBalance: Initial savings in dollars
interestRate = 0.025; % 2.5 percent annual interest rate
% Complete the for loop to iterate from 1 to numberYears (inclusive)
for year = 1:numberYears
savingsBalance = savingsBalance + (savingsBalance * interestRate);
end
end
```
In this function:
- The `for` loop iterates from 1 to `numberYears`.
- During each iteration, the `savingsBalance` is updated by adding the interest earned for that year, which is `savingsBalance * interestRate`.
1. Function Purpose: The function `CalculateBalance` takes two input arguments: `numberYears` (the number of years that interest is applied to savings) and `savingsBalance` (the initial savings amount in dollars). Its purpose is to calculate the total savings balance after applying interest over the specified number of years.
2. Interest Rate: The variable `interestRate` is defined within the function to represent the annual interest rate, which is set to 2.5%. This value is expressed as a decimal (0.025) for mathematical calculations.
3. For Loop: The heart of the function lies in the `for` loop, which iterates from 1 to `numberYears` (inclusive). This loop represents each year over which interest is applied to the savings balance.
4. Interest Calculation: Within the loop, the savings balance (`savingsBalance`) is updated in each iteration to reflect the accumulated interest. The formula `savingsBalance = savingsBalance + (savingsBalance * interestRate)` calculates the interest earned for the current year (2.5% of the current balance) and adds it to the existing balance. This process repeats for each year specified by `numberYears`, effectively simulating the accumulation of interest over time.
5. Return Value: Finally, the function returns the updated `savingsBalance` after all iterations of the `for` loop have been completed. This value represents the total savings balance after applying interest for the specified number of years.
Overall, the function provides a straightforward and efficient way to compute the savings balance over time, making it a useful tool for financial calculations.
Create a class named Billing that includes three overloaded computeBill() methods for a photo book store. When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8% tax, and return the total due. When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 8% tax, and return the total due. When computeBill() receives three parameters, they represent the price of a photo book, the quantity ordered, and a coupon value. Multiply the quantity and price, reduce the result by the coupon value, and then add 8% tax and return the total due. Write a main() method that tests all three overloaded methods. Save the application as Billing.java.
Answer:
Following are the program in the Java Programming Language.
//define class
public class Billing
{
//define method
public static double computeBill(double Price)
{
//declare variable and initialize the rate method
double taxes = 0.08*Price;
//print the output
return Price+taxes;
}
//override the following function
public static double computeBill(double Price, int quant) {
//declare double type variable
double taxes = 0.08*(Price*quant);
//return the output
return (quant*Price)+taxes;
}
//override the function
public static double computeBill(double Price, int quant,double value) {
//declare double type variable
double taxes = 0.08*(Price*quant);
//return the output
return ((quant*Price)+taxes)-value;
}
//define main method
public static void main(String args[]) {
//call the following function with argument
System.out.println(computeBill(10));
System.out.println(computeBill(10, 2));
System.out.println(computeBill(10, 20, 50));
}
}
Output:
10.8
21.6
166.0
Explanation:
Following are the description of the program.
Define class 'Billing', inside the class we override the following function.Define function 'computeBill()', inside it we calculate tax.Then, override the following function 'computeBill()' and pass the double data type argument 'Price' and integer type 'quant' then, calculate tax.Again, override that function 'computeBill()' and pass the double type arguments 'Price', 'value' and integer type 'quant' then, calculate tax.Finally, define the main method and call the following functions with arguments.The Billing class has three overloaded computeBill methods to calculate the total price of photo books with 8% tax. The methods vary by one, two, or three parameters for price, quantity, and coupon value respectively. The main method tests all three computeBill methods.
Let's create a Billing class with three overloaded computeBill() methods.
Here is the Java implementation:
public class Billing {Write a program to solve a quadratic equation. The program should allow the user to enter the values for a, b, and c. If the discriminant is less than zero, a message should be displayed that the roots are imaginary; otherwise, the program should then proceed to calculate and display the two roots of the eqaution. (Note: Be certain to make use of the squareRoot () function that you developed in this chapter.) (In C language)
Hint: This should not be too hard. You need to get some numbers from the user, do some calculations, check if the discriminate is negative, then use the textbook author’s squareRoot function to finish up the calculations!
program 7.8:
// Function to calculate the absolute value of a number
#include
float absoluteValue(float x)
{
if (x < 0)
x = -x;
return (x);
}
// Function to compute the square root of a number
float squareRoot(float x)
{
const float espsilon = .00001;
float guess = 1.0;
while (absoluteValue(guess * guess - x) >= espsilon)
guess = (x / guess + guess) / 2.0;
return guess;
}
int main(void)
{
printf("squareRoot (2.0) = %f\n", squareRoot(2.0));
printf("squareRoot (144.0) = %f\n", squareRoot(144.0));
printf("SquareRoot (17.5) = %f\n", squareRoot(17.5));
return 0;
}
Answer:
int main(void) { float a, b, c, discriminant, root1, root2; printf("Enter value for a, b and c:"); scanf("%f %f %f", &a, &b, &c); discriminant = b * b - 4 * a * c; if(discriminant < 0){ printf("The roots are imaginary"); }else{ root1 = (-b + squareRoot(discriminant)) / (2*a); root2 = (-b - squareRoot(discriminant)) / (2*a); printf("Root 1: %f", root1); printf("Root 2: %f", root2); } return 0; }Explanation:
Firstly, we declare all the required variables (Line 3) and then get user input for a , b and c (Line 4-5).
Next, apply formula to calculate discriminant (Line 7).
We can then proceed to determine if discriminant smaller than 0 (Line 9). If so, display the message to show the roots are imaginary (Line 10).
If not, proceed to calculate the root 1 and root 2 (Line 12-13) and then display the roots (Line 15 -16)
Answer:
// Program to calculate the roots of a quadratic equation
// This program is written in C programming language
// Comments are used for explanatory purpose
// Program starts here
#include<stdio.h>
#include<math.h>
int main()
{
// For a quadratic equation, ax² + bx + c = 0, the roots are x1 and x2
// where d =(b² - 4ac) ≥ 0
// Variable declaration
float a,b,c,d,x1,x2;
// Accept inputs
printf("Enter a, b and c of quadratic equation: ");
scanf("%f%f%f",&a,&b,&c);
// Calculate d
d = (b*b) - (4*a*c);
// Check if d > 0 or not
if(d < 0){ // Imaginary roots exist
printf("The roots are imaginary");
}
else // Real roots exist
{
// Calculate x1 and x2
x1= ( -b + sqrt(d)) / (2* a);
x2 = ( -b - sqrt(d)) / (2* a);
// Print roots
printf("Roots of quadratic equation are: %.3f , %.3f",x1,x2);
}
return 0;
}
return 0;
}
Question 2. Complete the following conditional statement so that the string 'More please' is assigned to the variable say_please if the number of nachos with cheese in ten_nachos is less than 5. Hint: You should not have to directly reference the variable ten_nachos.
Answer:
The solution code is written in Python 3:
ten_nachos = [True, True, False, False, False, True, False, True, False, False] count = 0 for x in ten_nachos: if (x == True): count += 1 if count < 5: say_please = "More please"Explanation:
By presuming the ten_nachos hold an array of True and False values with True referring to nachos with cheese and False referring to without cheese (Line 1).
We create a counter variable, count to track the occurrence of True value in the ten_nachos (Line 3).
Create a for-loop and traverse through the True and False value in the ten_nachos and then check if the current value is True, increment count by 1 (Line 5 - 7).
If the count is less than 5, assign string "More please" to variable say_please (Line 9 -10).
Final answer:
The question requires creating a conditional statement to assign a string to a variable based on a comparison. The statement would look something like 'if nacho_count < 5: say_please = 'More please'' in pseudocode, where 'nacho_count' represents the variable for the number of nachos.
Explanation:
The student's question involves completing a conditional statement in a programming context. The problem provided requires constructing logic that assigns the string 'More please' to a variable say_please based on the condition of the number of nachos with cheese being less than five. This scenario is aligned with conditional programming logic, often taught in computer science classes at the high school level. The completion of the conditional statement can be achieved by setting a variable (presumably counting the number of nachos) and checking if it is less than five.
For the given scenario, assuming the variable counting nachos is nacho_count, the conditional statement in pseudocode would look something like:
if nacho_count < 5:
say_please = 'More please'
It is important to note that in actual code, the specifics of the syntax will depend on the programming language being used. The underlying concept of using a conditional statement (if statement) to control the flow of a program, however, remains the same across different languages.
Create a class called Clock to represent a Clock. It should have three private instance variables: An int for the hours, an int for the minutes, and an int for the seconds. The class should include a threeargument constructor and get and set methods for each instance variable. Override the method toString which should return the Clock information in the same format as the input file (See below). Read the information about a Clock from a file that will be given to you on Blackboard, parse out the three pieces of information for the Clock using a StringTokenizer, instantiate the Clock and store the Clock object in two different arrays (one of these arrays will be sorted in a later step). Once the file has been read and the arrays have been filled, sort one of the arrays by hours using Selection Sort. Display the contents of the arrays in a GUI that has a GridLayout with one row and two columns. The left column should display the Clocks in the order read from the file, and the right column should display the Clocks in sorted order.
Answer:
public class Clock
{
private int hr; //store hours
private int min; //store minutes
private int sec; //store seconds
public Clock ()
{
setTime (0, 0, 0);
}
public Clock (int hours, int minutes, int seconds)
{
setTime (hours, minutes, seconds);
}
public void setTime (int hours, int minutes, int seconds)
{
if (0 <= hours && hours < 24)
hr = hours;
else
hr = 0;
if (0 <= minutes && minutes < 60)
min = minutes;
else
min = 0;
if (0 <= seconds && seconds < 60)
sec = seconds;
else
sec = 0;
}
//Method to return the hours
public int getHours ( )
{
return hr;
}
//Method to return the minutes
public int getMinutes ( )
{
return min;
}
//Method to return the seconds
public int getSeconds ( )
{
return sec;
}
public void printTime ( )
{
if (hr < 10)
System.out.print ("0");
System.out.print (hr + ":");
if (min < 10)
System.out.print ("0");
System.out.print (min + ":");
if (sec < 10)
System.out.print ("0");
System.out.print (sec);
}
//The time is incremented by one second
//If the before-increment time is 23:59:59, the time
//is reset to 00:00:00
public void incrementSeconds ( )
{
sec++;
if (sec > 59)
{
sec = 0;
incrementMinutes ( ); //increment minutes
}
}
///The time is incremented by one minute
//If the before-increment time is 23:59:53, the time
//is reset to 00:00:53
public void incrementMinutes ( )
{
min++;
if (min > 59)
{
min = 0;
incrementHours ( ); //increment hours
}
}
public void incrementHours ( )
{
hr++;
if (hr > 23)
hr = 0;
}
public boolean equals (Clock otherClock)
{
return (hr == otherClock.hr
&& min == otherClock.min
&& sec == otherClock.sec);
}
}