Answer:
C
Explanation:
You should make a string where they enter the vaulue and you calculate the interest by multipliying then the code should look like this input balance
balance=0 then they would select the amount and 0+entered amount times interest im 12 btw so
Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store.
Complete Question:
Create a program that compares the unit prices for two sizes of laundry detergent sold at a grocery store. Console Price Comparison Price of 64 oz size: 5.99 Price of 32 oz size: 3.50 Price per oz (64 oz): 0.09 Price per oz (32 oz): 0.11
Using Python
Answer:
This program does not make use of comments (See explanation section)
price64 = float(input("Price of 64 oz size: "))
price32 = float(input("Price of 32 oz size: "))
unit64 = price64/64
unit32 = price32/32
print("Unit price of 64 oz size: ", round(unit64,2))
print("Unit price of 32 oz size: ", round(unit32,2))
if unit64>unit32:
print("Unit price of 64 oz is greater" )
else:
print("Unit price of 32 oz is greater" )
Explanation:
This line prompts the user for the price of 64 oz size
price64 = float(input("Price of 64 oz size: "))
This line prompts the user for the price of 32 oz size
price32 = float(input("Price of 32 oz size: "))
This line calculates the unit price of 64 oz size
unit64 = price64/64
This line calculates the unit price of 32 oz size
unit32 = price32/32
This next two lines print the unit prices of both sizes
print("Unit price of 64 oz size: ", round(unit64,2))
print("Unit price of 32 oz size: ", round(unit32,2))
The next line compares the unit prices of both sizes
if unit64>unit32:
This line is executed if the unit price of 64 oz is greater than 32 oz
print("Unit price of 64 oz is greater" )
else:
This line is executed, if otherwise
print("Unit price of 32 oz is greater" )
Write a program with loops that compute: (10 points total) 1. Use a loop to sum the even numbers from 2 to 100 (inclusive) 2. Compute the sum of all of the squares from 1 to 10 (exlusive). 3. Compute all powers of 2 from 2 ** 0 to 2 ** 20 (inclusive). 4. Compute the sum of all odd integers between a and b(inclusive) where a and b are inputs. 5. Compute the sum of the odd digits in an input. For example: If the input is "32a7b79" then sum
Answer:
Following are the code of this question:
print("1:")
even_sum= 0;#declaring even_sum variable
for i in range(2, 101):#defining loop to count number from 2 to 100
if(i%2 == 0):#defining if block to count even number
even_sum=even_sum+i#add even numbers in even_sum variable
print (even_sum)#print even_sum
print("2:")
sum_suares= 0#declaring sum_suares variable
for i in range(1, 11):#defining loop to count square from 1 to 10
sum_suares= sum_suares+i*i # add square value
print (sum_suares)#print sum_suares value
print("3:")
for i in range(0, 21):# defining loop to count from 0 to 20
print ("Power of 2^",i," = ",pow(2,i))#print value
print("4:")
a = int(input('Enter first number:'))#defining a variable for user input
b = int(input('Enter second number:'))#defining b variable for user input
odd_sum = 0#defining odd_sum variable and assign value 0
for i in range(a, b+1):# defining loop that count from A to B+1
if(i%2 == 1):# defining if condition to check odd numbers and add value in odd_sum
odd_sum =odd_sum+i#add value in odd_sum variable
print (odd_sum)#print odd_sum value
print("5:")
number=input("Enter number : ")#defining number varaible for user input
odd_sum=0 #defining variable odd_sum that store value 0
for i in number: #defining loop to count odd number checking each digit
if int(i)%2!=0: #checking odd number
odd_sum=odd_sum+int(i)#add odd numbers
print(odd_sum)
Output:
please find the attachment.
Explanation:
Description of the given code can be defined as follows:
In the first program, it prints the sum of the even number from 2 to 100.In the second program, it first calculates the square from 1 to 10 and then adds all square values.In the third program, it calculates the power of the 2 from 0 to 20.In the fourth program, it first inputs two values "a, b", after input it calculates odd number then adds its values.In the fifth program, it inputs value from the user ends then, splits the value then adds odds number values.A school has 100 lockers and 100 students. All lockers are closed on the first day of school. As the students enter, the first student, denoted S1, opens every locker. Then the second student, S2, begins with the second locker, denoted L2, and closes every other locker (i.e. every even numbered locker). Student S3 begins with the third locker and changes every third locker (closes it if it was open, and opens it if it was closed). Student S4 begins with locker L4 and changes every fourth locker. Student
S5 starts with L5 and changes every fifth locker, and so on, until student S100 changes L100.
After all the students have passed through the building and changed the lockers, which lockers areopen? Write a program to find your answer.
(Hint: Use an array of 100 boolean elements. each of which indicates whether a locker is open (true) or closed (false). Initially, all lockers are closed.)
Answer:
Following are the code to this question:
public class Locker //defining a class Locker
{
public static void main(String[] ax)//defining main method
{
boolean[] locker = new boolean[101]; //defining boolean array locker that's size is 100.
int j,s1,k1,x;
x=locker.length;
for (j=1;j<x; j++)//defining loop to assigns value false in locker array
{
locker[j] = false;// assign value false
}
for (j=1;j<x; j++)//defining loop loop to assign value true in array
{
locker[j] = true;//assign value true
}
for(s1=2; s1<x; s1++)//defining loop to count locker from 2nd place
{
for(k1=s1; k1<x; k1=k1+s1)// defining inner loop to assign value
{
if(locker[k1]==false) //defining if block for check false value
{
locker[k1] = true;// if condition is true it assign value true
}
else //defining else block
{
locker[k1] = false;//assign value false in locker array
}
}
}
for(s1=1; s1<x; s1++)//defining loop to print locker value
{
if (locker[s1] == true) //defining if block that check Locker array value is equal to true
{
System.out.println("Locker " + s1 + " Open");//print Locker value with message
}
}
}
}
Output:
Locker 1 Open
Locker 4 Open
Locker 9 Open
Locker 16 Open
Locker 25 Open
Locker 36 Open
Locker 49 Open
Locker 64 Open
Locker 81 Open
Locker 100 Open
Explanation:
In the above code, a class "Locker" is declared, inside the class main method is declared, in which a boolean array "locker" is declared that's size is 100, in the next line fouth integer variable " j,s1,k1, and x" is declared, in which variable x is used to hold the boolean array length value, and other variable used in the loop.
In the next step, two for loop is declared, in the first loop assign value "false" in locker array and in seconde loop it assigns the value "true".In the next step, multiple for loop it uses if block uses to check locker value equal to false then assign value true otherwise assign value false. At the last another loop is declared, that uses if block to check locker value is equal to true and print its value with the message.If the object instance is created in a user program, then the object instance can access both the public and private members of the class using DOT notation (such as Rectangle r; r.area=10). True or False
Answer:
False
Explanation:
The private member of a class is not accessible by using the Dot notation ,however the private member are those which are not accessible inside the class they are accessible outside the class .The public member are accessible inside the class so they are accessible by using the dot operator .
Following are the example is given below in C++ Language
#include<iostream> // header file
using namespace std;
class Rectangle
{
private:
double r; // private member
public:
double area()
{ return 3.14*r*r;
}
};
int main()
{
Rectangle r1;// creating the object
r1.r = 3.5;
double t= r1.area(); // calling
cout<<" Area is:"<<t;
return 0;
}
Output:
compile time error is generated
The correct program to access the private member of class is given below
#include<iostream> // header file
using namespace std;
class Rectangle
{
private:
double r; // private member
public:
double area()
{
r1=r;
double t2=3.14*r2*r2;
return(t2); // return the value
}
};
int main()
{
Rectangle r1;// creating the object
r1.r = 1.5;
double t= r1.area(); // calling
cout<<" Area is:"<<t;
return 0;
}
Therefore the given statement is False
Write the code to read 3 input values for the length, height and width of a cuboid, then calculate the area and circumference.
Answer:
length = float(input("Enter the length: "))
height = float(input("Enter the height: "))
width = float(input("Enter the width: "))
area = 2 * (length * height + height * width + width * length)
circumference = 4 * (length + height + width)
print("The area is: " + str(area))
print("The circumference is: " + str(circumference))
Explanation:
*The code is in Python.
Ask the user to enter the length, height and width
Calculate the area and circumference using the formulas and print them
Open source companies like Ethereum and Codius are enabling Smart Contracts using blockchain technology.
a. True
b. False
Answer:
True
Explanation:
Ethereum uses Smart Contracts Blockchains and one of the programmers actually explained how it works at a DC Blockchain Summit.
Answer:
True.
Explanation:
In 2018, Cryptanite Blockchain Technologies Corp. (CSE: NITE), a Boulder-based blockchain technology company, today announced the launch of hosting capabilities with Codius, an open-source platform that enables the hosting of smart contracts and apps powered by the Ripple blockchain. Publicly listed in both Canada and in Germany, Cryptanite is one of the first companies to market with Codius’ hosting capabilities.
hich IP address is assigned to a network connection if the TCP/IP settings are set for static IP addressing and a DHCP server is running on the network?
Question:
Which IP address is assigned to a network connection if the TCP/IP settings are set for static IP addressing and a DHCP server is running on the network?
A) An Automatic Private IP Addressing (APIPA) IP address is used
B) An error will occur and no IP address is assigned unless it is manually assigned at a command prompt
C) The IP address configured in the Internet Protocol Version 4 (TCP/IPv4) dialogue box is used
D) The IP address assigned by the DHCP server is used
Answer:
The correct answer is C
Explanation:
After the settings are changed from automatic to static, one must enter the address manually using the dialogue box and the spaces provided therein.
Any attempt to click okay will display an error requesting that the IP address be entered manually.
Static IP addresses are used when you don't want the Internet Protocol (IP) address to change.
Cheers!
"Players The files SomePlayers.txt initially contains the names of 30 football play- ers. Write a program that deletes those players from the file whose names do not begin with a vowel."
Answer:
I am writing a Python program that deletes players from the file whose names whose names do not begin with a vowel which means their names begin with a consonant instead. Since the SomePlayers.txt is not provided so i am creating this file. You can simply use this program on your own file.
fileobj= open('SomePlayers.txt', 'r')
player_names=[name.rstrip() for name in fileobj]
fileobj.close()
vowels = ('a', 'e', 'i', 'o', 'u','A','E','I','O','U')
player_names=[name for name in player_names
if name[0] in vowels]
fileobj.close()
print(player_names)
Explanation:
I will explain the program line by line.
First SomePlayers.txt is opened in r mode which is read mode using open() method. fileobj is the name of the file object created to access or manipulate the SomePlayers.txt file. Next a for loop is used to move through each string in the text file and rstrip() method is used to remove white spaces from the text file and stores the names in player_names. Next the file is closed using close() method. Next vowels holds the list of characters which are vowels including both the upper and lower case vowels.
player_names=[name for name in player_names
if name[0] in vowels]
This is the main line of the code. The for loop traverses through every name string in the text file SomePlayers.txt which was first stored in player_names when rstrip() method was used. Now the IF condition checks the first character of each name string. [0] is the index position of the first character of each players name. So the if condition checks if the first character of the name is a vowel or not. in keyword is used here to check if the vowel is included in the first character of every name in the file. This will separate all the names that begins with a vowel and stores in the list player_names. At the end the print statement print(player_names) displays all the names included in the player_names which begin with a vowel hence removing all those names do not begin with a vowel.
Design a two-thread consensus protocol for a Stack class that provides two methods: push(x) and pop(). push(x) pushes a value onto the top of the stack, and pop() removes and returns the most recently pushed value.
Answer:
D. 10, 5.
Explanation:
#Write a function called "angry_file_finder" that accepts a #filename as a parameter. The function should open the file, #read it, and return True if the file contains "!" on every #line. Otherwise the function should return False. # #Hint: there are lots of ways to do this. We'd suggest using #either the readline() or readlines() methods. readline() #returns the next line in the file; readlines() returns a #list of all the lines in the file. #Write your function here!
Answer:
I am writing a Python function:
def angry_file_finder(filename): #function definition, this function takes file name as parameter
with open(filename, "r") as read: #open() method is used to open the file in read mode using object read
lines = read.readlines() #read lines return a list of all lines in the file
for line in lines: #loops through each line of the file
if not '!' in line: #if the line does not contains exclamation mark
return False # returns False if a line contains no !
return True # returns true if the line contains exclamation mark
print(angry_file_finder("file.txt")) call angry_file_finder method by passing a text file name to it
Explanation:
The method angry_file_finder method takes a file name as parameter. Opens that file in read mode using open() method with "r". Then it reads all the lines of the file using readline() method. The for loop iterates through these lines and check if "!" is present in the lines or not. If a line in the text file contains "!" character then function returns true else returns false.
There is a better way to write this method without using readlines() method.
def angry_file_finder(filename):
with open(filename, "r") as file:
for line in file:
if '!' not in line:
return False
return True
print(angry_file_finder("file.txt"))
Above method opens the file in read mode and just uses a for loop to iterate through each line of the file to check for ! character. The if condition in the for loop checks if ! is not present in a line of the text file. If it is not present in the line then function returns False else it returns True. This is a more efficient way to find a character in a file.
When discussing the behavior of vulnerability assessments which choice will exploit a weakness?
a) Penetration test
b) Vulnerability scan
c) Intrusive
d) Gray box
e) Credentialed vulnerability scan
f) Non-credentialed vulnerability scan
Answer:
a) Penetration test
Explanation:
A penetration test, often referred to as a pen test, is part of important process in the development of internet facing service. It is a process of determining if vulnerabilities are actually exploitable in a particular environment.
In other words, it is a process that involves a simulated cyber attack against computer system to check for exploitable vulnerabilities or attempts to actively exploit weaknesses in an environment.
Hence, when discussing the behavior of vulnerability assessments the choice that will exploit a weakness is PENETRATION TEST.
When discussing the behavior of vulnerability assessments, the choice which will exploit a weakness is: A) Penetration test.
Cyber security can be defined as a preventive practice to systematically protect computers, software applications (programs), networks, electronic devices, servers and user data from potential attack, damage, theft or an unauthorized access, especially through the use of technologies, frameworks, integrity principles, processes, penetration test and network engineers.
A vulnerability can be defined as a weakness in an automated internal control system and security procedures, which may be exploited by an attacker (hacker) to gain unauthorized access to the data stored on a computer system or disrupt the information system.
Basically, vulnerability assessments can be used in the following ways:
Identify loopholes, risks and security threats. Prioritize and enhance an information system.Mitigate potential security threats.A penetration test is also referred to as pen test or ethical hacking and it can be defined as a cybersecurity technique that simulates a cyber attack against a user's computer system, so as to identify, test an check for exploitable vulnerabilities in a web software, network, etc.
This ultimately implies that, a penetration test avails an end user the ability to exploit a weakness and potential security threats during vulnerability assessments.
An IT engineer is planning a website upgrade with load balancing features. What technology is used? A) Web Proxy B) Round Robin C) Port Forwarding D) Reverse Proxy
Answer: (B): Round Robin
Explanation: Load Balancing refers to the systemic and effective distribution of network or application traffic across multiple severs in a sever farm. Every algorithm that balances load sits between the client's device and the back end severs.
Load Balancers are majorly used to increase the reliability and capacity of applications.
Round Robin is a type of algorithm that can be used to upgrade a website with load balancing features. It is the most widely used load balancing algorithm and it is a simple way to distribute requests across a group of servers.
The type of technology an IT engineer that is planning a website upgrade with load balancing features would use is: D) Reverse Proxy.
A website can be defined as a collective name used to describe series of web pages that are linked together with the same domain name.
A web server is a type of computer that run websites and distribute web pages as they are being requested over the internet by end users (clients).
Basically, when an end user (client) request for a website by adding or typing the uniform resource locator (URL) on the address bar of a web browser; a request is sent to the internet to view the corresponding web pages (website) associated with that particular address (domain name).
In Computer Networking, a single server can be configured to appear as an endpoint for multiple servers acting behind it through the use of a reverse proxy.
Hence, a reverse proxy is a type of server that is placed right in front of other servers such as a web server and it is typically configured to forward or route an end user's requests to those multiple servers sitting behind it.
Furthermore, when a reverse proxy is properly configured, it helps to ensure security, reliability and optimum performance of a network through load balancing.
Therefore, server load balancing is a process that allows the even distribution of network traffic across multiple servers and it involves the use of a technology referred to as a reverse proxy.
Find more information: https://brainly.com/question/17235457
To configure a router / modem, what type of IP interface configuration should you apply to the computer you are using?
Answer:
hello your question has some missing parts
To configure a router / modem, what type of IP interface configuration should you apply to the computer you are using to access the device administration web app?
answer ; Gigabit interface
Explanation:
To configure a router/modem the type of IP interface configuration you should apply to the computer you are using to access the the devices administration web app should be Gigabit interface.
This is because Gigabit interface offers a very efficient and high band width and also a very high speed link which operates at 1000 Mbps, or 1 Gbps and it is the the standard used due to the speed it offers as it also offers improved performance over Ethernet
A(n) ___________ analyzes traffic patterns and compares them to known patterns of malicious behavior.
Answer:
Intrusion detection system
Explanation:
An intrusion detection system (IDS) is a device or software application that monitors a network for malicious activity or policy violations. Any malicious activity or violation is typically reported or collected centrally using a security information and event management system.
In e-mail, SSL/TLS provides ________. link encryption end-to-end encryption both link encryption and end-to-end encryption neither link encryption nor end-to-end encryption
Answer:
link encryption
Explanation:
In e-mail, SSL/TLS provides link encryption.
The SSL is an acronym for Secured Socket Layer and it is one of the secured way of authenticating and encrypting data between a computer and the mail server.
In the case of a TLS, it is an acronym for Transport Layer Security and it basically is used for providing authentication and encryption of data between two communicating systems on a network.
This ultimately implies that, SSL/TLS are standard network protocols that provides data integrity and privacy to users when communicating over the internet or networking devices as they're made to encrypt user credentials and data from unauthorized access. The SSL/TLS are an application layer protocol used for the encryption of mails sent over the internet, in order to protect user information such as username and password.
Universal Containers (UC) has decided to build a new, highly sensitive application on the Force platform. The security team at UC has decided that they want users to provide a fingerprint in addition to username/password to authenticate to this application. How can an Architect support fingerprints as a form of identification for Salesforce authentication
Use an AppExchange product that does fingerprint scanning with native Salesforce Identity Confirmation
If we used an inadmissible heuristic in A* tree search, could it change the completeness of the search?
Answer:
No
Explanation:
If we used an inadmissible heuristic in A* tree search, it cannot change the completeness of the search, and this is because as long as a heuristic function is bounded, then A* tree search would visit all the nodes available and would definitely find a path to an existing goal
A* tree search is a search strategy that is used to find and establish an efficient path between points, and the node in a search tree can be visited several times as well
Given input characters for an arrowhead and arrow body, print a right-facing arrow. Ex: If the input is: *
Answer:
Following are the code to this question:
b= input()#defining b variable for input character value
h= input()#defining h variable for input character value
b_width=6#defining b_width variable that holds an integer value 6
r1 = ' ' * b_width+h#defining r1 variable that calculates hash lines
r2 = b*b_width+h*2#defining r3 variable that calculates 6 asterisk and 2 hash line
r3 = b*b_width+h*3#defining r3 variable that calculates 6 asterisk and 3 hash line
print(r1)#print r1 variable value
print(r2)#print r2 variable value
print(r3)#print r3 variable value
print(r2)#print r2 variable value
print(r1)#print r1 variable value
Output:
please find the attachment.
Explanation:
In the given python code, three variable "b,h, and b_width" is declared, in which "b_width" holds an integer variable "6" and variable "b and h" is used to an input character value. In the next line, "r1, r2, and r3" is declared, that holds arrowhead values which can be defined as follows:
In the "r1" variable, it stores space with b_width variable and one h variable value.In the "r2" variable it stores b_width and 2*h variable value. In the "r3" variable it stores b_width and 3*h variable value.At the last, it prints the "r1, r2, and r3" variable value and for arrowheads, it follows the above program code.
Answer:
base_char = input()
head_char = input()
row1 = ' ' + head_char
row2 = base_char*6+head_char*2
row3 = base_char*6+head_char*3
print(row1)
print(row2)
print(row3)
print(row2)
print(row1)
Explanation:
The Secure Sockets Layer which relies on __________ for encrypting the data between client and server
Answer: symmetric encryption
Explanation:
The Secure Sockets Layer (SSL) protocol is required by the Web servers and the web browsers in order to protect the data of the users during transfer through the creation of an encrypted channel that is unique for private communications that occur over the Internet.
The Secure Sockets Layer relies on the encryption in order to secure the link that exists between the client and the server which is the website.
This implies that the encryption and also the decryption of the data will be done using a cryptographic key that is shared. The cryptographic key will be generated and shared on accordance with transport layer security handshake.
To copy a selected file to an external drive, right-click the file, point to __________ on the shortcut menu, and then click the drive, such as Drive E:.
Answer:
send to
Explanation:
method of copy and move fro shortcut menu is
for copy : right click a file and than click copy shortcut menu, right click the final location folder and than click on paste or CTRL + C and then CTRl + V
and
for move: right click a file and than click cut shortcut menu, right click the final location folder and than click on paste . or CTRL + X and then CTRl + V
Create an array named itemDescription containing the following item descriptions:
a) 1975 Green Bay Packers Football (signed), Item 10582
b) Tom Landry 1955 Football Card (unsigned), Item 23015
c) 1916 Army-Navy Game, Framed Photo (signed), Item 41807
d) Protective Card Sheets, Item 10041.
Answer:
var itemDescription = ["1975 Green Bay Packers Football (signed), Item 10582", "Tom Landry 1955 Football Card (unsigned), Item 23015", "1916 Army-Navy Game, Framed Photo (signed), Item 41807", "Protective Card Sheets, Item 10041"];
Explanation:
The following solution will work with javascript. Here we've stored different items in a variable named itemDescription.
Which term describes the order of arrangement of files and folders on a computer? is the order of arrangement of files and folders.
Answer:
Organization
Explanation:
The term that describes the order of arrangement of files and folders on a computer is organization. It is very important the organization of the files and folders to be effective, in order to work with them quickly and efficiently.
Answer:
The term that describes the order of arrangement of files and folders on a computer is organization.
Explanation:
g java 18.6 [Contest 6 - 07/10] Reverse an array Reversing an array is a common task. One approach copies to a second array in reverse, then copies the second array back to the first. However, to save space, reversing an array without using a second array is sometimes preferable. Write a function that reads in an integer representing the length of the array. Then read in and reverse the given array, without using a second array. If the original array's values are 2 5 9 7, the array after reversing is 7 9 5 2. Write a method to reverse the input array and call the method in the main. Note: The first item in the input is the length of the input array. The rest of the items in the input are the elements stored inside of the input array. Hints: Use this approach: Swap the first and last elements, then swap the second and second-to-last elements, etc. Stop when you reach the middle; else, you'll reverse the vector twice, ending with the original order. Think about the case when the number of elements is even, and when odd. Make sure your code handles both cases.
Answer:
I am writing a JAVA program:
import java.util.Scanner; //Scanner class is used to take input from user
public class ReverseArray{ //class to reverse the input array
static void reverse(int array[], int size){ //method to reverse an array
int i, j, temp; //declare variables
for (i = 0; i < size / 2; i++) { /* the loop swaps the first and last elements, then swap the second and second-to-last elements and so on until the middle of the array is reached */
temp = array[i];
array[i] = array[size - i - 1];
array[size - i - 1] = temp; }
System.out.println("Reversed array: \n"); //prints the resultant reversed array after swapping process
for (j = 0; j < size; j++) { //loop to print the reversed array elements
System.out.println(array[j]); } }
public static void main(String[] args) { //start of main() function body
Scanner input=new Scanner(System.in); // create Scanner class object
System.out.println("Enter the length of array: "); //prompts user to enter the length of the array
int n =input.nextInt(); //scans and reads the input size of array
int A[]=new int[n]; // creates an array of size n
System.out.println("Enter the elements: "); //prompts user to enter array elements
for(int i=0;i<n;i++){ //loop for reading the elements of array
A[i]=input.nextInt(); }
reverse(A,n); }} //calls reverse function to reverse the elements of the input array A by passing array A and its length n to function reverse
Explanation:
The reverse function takes an array and its length as parameter. In the body of reverse function three integer type variables i,j and temp are declared.
for (i = 0; i < size / 2; i++) The for loop has a variable to iterate through the array. The for loop checks if the value of i is less than the array length. Lets say we have an array of elements 1, 2, 3, 4. As i=0 and size/2 = 4/2= 2. So the condition checked in for loop is true as 0<2 which means the body of for loop will be executed.
In the body of the loop there are three swap statements.
temp = array[i] This statement stores the element of array at i-th index to temp variable.
array[i] = array[size - i - 1] statement stores the element of array at size-i-1 to array index i.
array[size - i - 1] = temp statement stores the the value in temp variable to the array index size-i-1
In simple words first, the first and last elements of array are swapped, then the second and second last elements are swapped. This process keeps repeating and for loop keeps executing these swap statements until the middle of the array is reached. In this program no extra array is used for reversing procedure but just a variable temp is used to hold the array elements temporarily.
array[4] = { 1 , 2 , 3 , 4}
At first iteration
i < size/2 is true as 0<2
So the program control moves in the body of the loop where three swap statement works as following:
temp = array[i]
temp = array[0]
As element at 0-th index which is the first element of array is 1 so
temp= 1
array[i] = array[size - i - 1];
array[0] = array[4-0-1]
= array[3]
As the element at 3rd index of array is 4 which is the last element of the array so
array[0] = 4
This means that 4 becomes the first element of array now.
array[size - i - 1] = temp
As the value in temp was set to 1 so
array[4-0-1] = 1
array[3] = 1
This means 1 is assigned to the 3rd index of array. Which means 1 becomes the last element of the array now.
This is how the first and last elements of array are swapped.
2nd iteration: value of i is incremented to 1 and now i = 1
Again for loop condition is checked which evaluates to true as 1<2
temp = array[i]
temp = array[1]
As element at 1st index which is the second element of array is 2 so
temp= 2
array[i] = array[size - i - 1];
array[1] = array[4-1-1]
= array[2]
As the element at second index of array is 3 which is the last element of the array so
array[1] = 3
This means that 3 becomes the second element of array now.
array[size - i - 1] = temp
As the value in temp was set to 2 so
array[4-1-1] = 2
This means 2 is assigned to the 2nd index of array. Which means 2 becomes the second last element of the array now.
This is how the second and second to last elements of array are swapped.
3rd iteration: value of i=2 The for loop body will not execute now as the for loop condition i<size-2 evaluates to false because 2=2. So the loop stops and next for (j = 0; j < size; j++) loop iterates through array[] which has now been reversed and print the elements of this reversed array.
Next the main() method passes length of the array and the array elements to the reverse function and prints these elements in reverse.
The output is:
4
3
2
1
If you do not want to take input from user then you can declare an array and assign elements to it as:
int [] A = {1, 2, 3, 4};
Then call reverse function by passing A[] and A.length which computes the length of the array
reverse(A, A.length);
The program and output according to the example 2,5,9,7 given in the question is attached as a screenshot.
#Write a function called align_right. align_right should #take two parameters: a string (a_string) and an integer #(string_length), in that order. # #The function should return the same string with spaces #added to the left so that the text is "right aligned" in a #string. The number of spaces added should make the total #string length equal string_length. # #For example: align_right("CS1301", 10) would return the #string " CS1301". Four spaces are added to the left so #"CS1301" is right-aligned and the total string length is #10. # #HINT: Remember, len(a_string) will give you the number of #characters currently in a_string.
Answer:
This program is written using Python Programming Language;
Comments are not used; however, see explanation section for detailed line by line explanation
See Attachment
Program starts here
def align_right(a_string,string_length):
if len(a_string) > string_length:
print(a_string)
else:
aligned=a_string.rjust(string_length)
print(aligned)
a_string = input("Enter a string: ")
string_length = int(input("Enter string length: "))
align_right(a_string,string_length)
Explanation:
Function align_right is declared using on line
def align_right(a_string,string_length):
This line checks if the length of the current string is greater than the input length
if len(a_string) > string_length:
If the above condition is true, the input string is printed as inputted
print(a_string)
If otherwise,
else:
The string is right justified using the next line
aligned=a_string.rjust(string_length)
The aligned string is printed using the next line
print(aligned)
The main function starts here
This line prompts user for a string
a_string = input("Enter a string: ")
This line prompts user for total string length
string_length = int(input("Enter string length: "))
This line calls the defined function
align_right(a_string,string_length)
Program your own file lab7.cpp in which your main() function will test the new data structure. The main() function, Declares an instance of BinarySearchTree (short: BST) suitable to hold integer values. Prompts user to enter a random sequence of integer values, inserts these values into the data structure (the entered values should NOT be in sorted order). Calls the print BAR() member function to print out the values of the BST structure. Prompts user to enter a random sequence of integer values, remove these values from your BST. Print out the reduced BST. Exercise 3: Write a function printRange that takes as input a binary search tree t and two keys, k1 and k2, which are ordered so that k1 < k2, and print all elements x in the tree such that k1 <= x <= k2. Add the following member function in your BinarySearchTree class template.
"Write a VBA function that changes the cell value of E3. Create a button on sheet 4 to increase the value by 1. Name this button "Higher". Then create a button below it that will decrease the number by 1 and name it "Lower". Save the function so we can review it."
Answer:
Please follow the steps
1) Open excel
2) Go to Developer Tools
3) Click on "Insert" and then under "ActiveX Controls", click on command button on extreme left.
4) Create two buttons and name them "Higher" and "Lower"
5) Double click on the button which you have named "Higher".
6) A new window will be opened where you have to put the code "Range("E3").Value = Range("E3").Value + 1".
7) Minimize the window and turn off the "Design View"
8) Put any value in E3 to verify the working and click the button named "Higher".
9) Perform the same steps for the button which you have named "Lower" and put the code "Range("E3").Value = Range("E3").Value - 1".
N.B: If you don't see the developer tools on the top. Click on the File menu and then select Options from the drop down menu. Excel Options window will appear.click on the Customize Ribbon option which you will see on the left. Click on the Developer checkbox under the list of Main Tabs on the right. Then click on the OK button.
Explanation:
"Crayon Colors The file ShortColors.txt initially contains the names of all the colors in a full box of Crayola crayons. Write a program that deletes all colors from the file whose name contains more than six characters."
Answer:
I am writing the Python program. Since you have not attached the ShortColors.txt file so i am taking my own text containing the names of the colors. You can use this program for your ShortColors.txt file.
infile = "ShortColors.txt"
outfile = "NewFile.txt"
f_read = open(infile)
f_write = open(outfile, "w+")
for name in f_read:
if len(name)<=7:
name.rstrip()
f_write.write(name)
f_read.close()
f_write.close()
Explanation:
I will explain the program line by line.
infile = "ShortColors.txt" creates an object named infile which is used to access and manipulate the text file ShortColors.txt. This file contains names of colors. This object will basically be used to access and read the file contents.
outfile = "NewFile.txt" creates an object named outfile which is used to access and manipulate the text file NewFile.txt. This text file is created to contain the colors from ShortColors.txt whose name contains less than or equal to six characters. This means NewFile.txt will contain the final color names after deletion of color names containing more than six characters.
f_read = open(infile) in this statement open() method is used to open the ShortColors.txt file. f_read is an object. Basically the text file is opened to read its contents.
f_write = open(outfile, "w+") in this statement open() method is used to open the NewFile.txt file. f_write is an object. Basically this text file is opened in w+ mode which means write mode. This is opened in write mode because after deleting the colors the rest of the colors with less than or equal to six characters are to be written in this NewFile.txt.
for name in f_read: this is where the main work begins to remove the colors with more than six characters. The loop reads each name from the ShortColors.txt file and here f_read object is used in order use this text file. This loop continues to read each name in the text file and executes the statements within the body of this loop.
if len(name)<=7: this if condition in the body of for loop checks if the length of the color name is less than or equal to 7. Here each character is counted from 0 to 6 so that is why 7 is used. To check the length of every color name len() method is used which returns the length of each name.
name.rstrip() this method rstrip() is used to remove the characters from each name whose length is greater than 6.
f_write.write(name) now write() method is used to write the names of all the colors with less than or equal to six characters in NewFile.txt. For this purpose f_write object is used.
Here i did not remove the colors from the original file ShortColors.txt to keep all the contents of the file safe and i have used NewFile.txt to display color names after deletion of all colors whose name contains more than six characters.
After the whole process is done both the files are closes using close() method.
Attached screenshots are of the program, the ShortColors.txt and NewFile.txt.
If a process does not call exec after forking, A. the program specified in the parameter to exec will replace the entire process B. all the threads should be duplicated C. all the threads should not be duplicated D. none of above
Answer:
b) all the threads should be duplicated
Explanation:
The fork provides a process to start a new one, and the new process is not the same program. The exec system call com in play. Exec replaces the currently running process with information. The process is launching a new program firstly fork and create a new process. Exec load into memory. Fork copies of all attribute the new process except for memory. A clone system call implements the kernel fork. Forking provides the existing process. And the thread should be duplicated.
Write a flowchart and C code for a program that does the following: Within main(), it asks for the user's annual income. Within main(), it calls a function called printIt() and passes the income value to printIt(). The printIt() function evaluates the income, and if the number is over 90000, it prints a congratulatory message. If the income is not over 90000, it prints a message of encouragement, like "You WILL make $50,000, if you keep going."
Answer:
I am writing a C program:
#include <stdio.h> //to use input output functions
void printIt(double annual_in){ //function printIt
if(annual_in >90000) //check if the income is greater than 90000
printf("Congratulations. Doing great!"); //print this message if income value is greater than 90000
else //if annual income is less than 90000
printf("You WILL make $50,000, if you keep going"); } //print this message if income value is less than 90000
int main() //start of main() funciton body
{ double income; //declares a double type variable income to hold annual income value
printf("Enter annual income: "); //prompts user to enter annual income
scanf("%lf",&income); //reads income value from user
printIt(income); } // calls printIt method by passing input income to that function
Explanation:
The program is well explained in the comments mentioned with each statement of the program. The flowchart is attached.
First flowchart flow1 has a separate main program flowchart which reads the income and calls printIt function. A second flowchart is of prinIt() method that checks the input income passed by main function and displays the corresponding messages and return.
The second flowchart flow2 is the simple flowchart that simply gives functional description of the C program as flowchart is not where giving function definitions is important. Instead of defining the function printIt separately for this C program, a high-level representation of functional aspects of this program is described in second flowchart while not getting into implementation details.
The U.S. continues to become more dependent on the global domain within the information environment consisting of the interdependent network of information technology infrastructures, including the Internet, telecommunications networks, computer systems, and embedded processors and controllers. It is imperative that we safeguard this domain known as
Answer:
"Cyberspace " is the right answer.
Explanation:
Cyberspace seems to be an interactive computational environment, unconstrained by distance and perhaps other functional disabilities. William Gibson developed the word for representing a sophisticated augmented reality infrastructure in his story Neuromancer.The virtual space generated over the network through synchronized computing devices.So that the above would be the correct answer.