In: Computer Science
C++ code won't run. Fix?
//==========================================================
#include <conio.h> // For function getch()
#include <cstdlib> // For several general-purpose
functions
#include <fstream> // For file handling
#include <iomanip> // For formatted output
#include <iostream> // For cin, cout, and system
#include <string> // For string data type
using namespace std; // So "std::cout" may be abbreviated to
"cout"
//Converting hexadecimal to binary
int main()
{
char binarynum[65], hexa[17];
//Using long int because it has greater capacity
long int i = 0;
printf("Enter the hex value that needs to convert
to binary: ");
scanf_s("%s", hexa);
printf("\n The converted hex value in binary is:
");
while (hexa[i])
{
//These are the different cases for
the binary that will be converted from hex. Case is the hex code
and printf is the binary output.
//It scans the inputs and then
compares it to switch case that is below.
switch (hexa[i])
{
case '0':
printf("0000");
break;
case '1':
printf("0001");
break;
case '2':
printf("0010");
break;
case '3':
printf("0011");
break;
case '4':
printf("0100");
break;
case '5':
printf("0101");
break;
case '6':
printf("0110");
break;
case '7':
printf("0111");
break;
case '8':
printf("1000");
break;
case '9':
printf("1001");
break;
case 'A':
printf("1010");
break;
case 'B':
printf("1011");
break;
case 'C':
printf("1100");
break;
case 'D':
printf("1101");
break;
case 'E':
printf("1110");
break;
case 'F':
printf("1111");
break;
case 'a':
printf("1010");
break;
case 'b':
printf("1011");
break;
case 'c':
printf("1100");
break;
case 'd':
printf("1101");
break;
case 'e':
printf("1110");
break;
case 'f':
printf("1111");
break;
//
default:
printf("\n
Invalid hexa digit entered ", hexa[i]);
return 0;
}
i++;
}
cout << "Press any key to
exit ..." << endl;
_getch();
}
In: Computer Science
// This program ask the user to enter a character. It then performs a
// linear search on a character array and display the number of times
// that the character appears on the array. If the character is not in the
// array, then it will display a message saying that is was not found.
// Add the necessary code for the program to work.
// NOTE:
// You don't have to edit anything in the main(), just in the searchArray() function.
// EXAMPLES:
// Input: Enter a letter to search for: h
// Output: The are 2 number of 'h' letters in the list
// Input: Enter a letter to search for: n
// Output: The are 2 number of 'n' letters in the list
// Input: Enter a letter to search for: z
// Output: The letter z was not found in the list
#include<iostream>
using namespace std;
int searchArray(char[], int, char); // function prototype
const int SIZE = 10;
int main()
{
//char charArray[SIZE] = {'h', 'h', 'a', 'r', 'p', 'o', 'o', 'n', 'n', '\0'};
char charArray[SIZE] = "hharpoonn";
int found;
char ch;
cout << "Enter a letter to search for: ";
cin >> ch;
found = searchArray(charArray, SIZE, ch);
if (found == 0)
cout << "The letter " << ch
<< " was not found in the array" << endl;
else
cout << "The are " << found << " number of '" << ch
<<"' letters in the array" << endl;
return 0;
}
//*******************************************************************
// searchArray
//
// task: This searches an array for a particular value
// data in: Array of values, the number of
// elements in the array, and the value searched for
// in the array
// data returned: Number of times the value appears in the list or 0
// if the value is not found
//
//*******************************************************************
int searchArray(char array[], int numElems, char value)
{
// Counter, contains the number of times the character appears on the array.
int count = 0;
// Add code to search the array and count the number of times the
// character appears in it.
// HINT: for-loop similar to the one in linearSearch.cpp
// Complete the return statement. If the value is found, returns the
// number of characters founded. If the value is not found, 0 is returned.
return _________;
}
In: Computer Science
Choose a topic from the course book. Explain the concept and discuss how the topic is relevant in today's cyber strategic operations. You may use the provided chapters of the book if you do not have the book. See link on the home page of this course.
*2 page answer
In: Computer Science
Linked List:
Complete the following code to create a linked list from an Array. After creating the list, display the elements of the linked list iteratively.
Write two others function called as RDisplayTailRecursion(first) and RDisplayTailRecursion(first) which will print elements of the linked list using the tail and head recursions respectively.
#include <stdio.h>
#include <stdlib.h>
struct Node
{
}*first=NULL;
void create(int A[], int n)
{
for(i=1; i<n; i++)
{
}
}
void Display(struct Node*p)
{
while(p!=NULL)
{
}
}
void RDisplayTailRecursion (struct Node*p)
{
if(p!=NULL)
{
}
}
void RDisplayHeadRecursion (struct Node*p)
{
if(p!=NULL)
{
}
}
int main()
{
struct Node *temp;
int A[] = {3,5,7,10,25,8,32,2};
create(A,8);
Display(first);
printf("\n");
RDisplayTailRecursion(first);
RDisplayTailRecursion(first);
return 0;
}
In: Computer Science
Caesar Cipher in Java Problem?
Objective
Practice the cumulative sum and char data type
Problem
You want to create an app to encrypt the text messages that you send to your friends. Once your friend gets the message, the message should be decrypted so that your friend understands it. To implement this app Caesar cipher algorithm should be used. Caesar Cipher text is formed by rotating each letter by a given amount. For example, if you rotate the letter ‘A’ by 3 you should get ‘D’. rotate ‘B’ by 3 you should get ‘E’. Toward the end of the alphabet you wrap around, if example rotate ‘X’ by 3 you should get ‘A’. rotate ‘Y’ by 3 you should get ’B’
Methods
Public static void main(String[] args)
public static void run(Scanner kb)
Public static String encrypt (String message, int key)
{
Convert the message to uppercase using the method toUpperCase from the String class
Declare a variable of type string called result to hold the encrypted message, initialize it to “”;
Create a loop to go through each letter of the message
{
Get each letter and store it in a variable of type char called c, use the charAt method: char c = message.charAt(i)
If the letter is between ‘A’ and ‘Z’
{
Add the key to the letter: c = c + key
//checking for wrap around
If c is greater than ‘Z’
{
Subtract 26 from c
}
else
{
Add 26 to c
}
}//end of if
Add the content of the variable c to the variable result (cumulative sum)
}//end of the loop
Return result
}//end of the method
Public static String decrypt (String message, int key):
{
Declare a String called result and initialize it to “”
Create a for loop to go through each letter of the message
{
Get the character at each index char c = message.charAt(i)
If the variable c is between ‘A’ and ‘Z’
{
Subtract the value of the variable key from the variable c
If the content of the variable c is less than ‘A’ //check for wrap around
{
Find the difference between the letter ‘A’ and the variable c : int diff = ‘A’ - c
c = (char)(‘Z’ – diff + 1)
}
else if c > ‘Z’ //
{
Int diff = ‘Z’ - c
C = (char)((‘A’ + diff + 1)
}
}
Concatenate the variable c to the variable result
}//end for
Return result
}//end of the method
Requirements
Sample output:
How many times to you want to use the app: 4
Your message? I love java programming
Encoding key? 5
The encrypted message is:
N QTAJ OFAF UWTLWFRRNSL
The decrypted message is:
I LOVE JAVA PROGRAMMING
In: Computer Science
You are the Chief of Cybersecurity Operations at a National Palace. Your organization will host a Gala for distinguished visitors. Discuss how you would plan and what you would consider in order to keep the event Cyber secure.
*2 page answer
In: Computer Science
Understanding Operating Systems
It seems, in this tough economy, people are resorting to borrowing books and DVDs from the library rather than buying or renting from stores. Your library continues to thrive. You have expanded and added staff - besides you, you now have two library assistants, Peter and Jane. Peter is assigned to receive returned books, DVDs, and magazines, while Jane is in charge of lending out books and items.
As you only have a finite amount of titles to lend, you have also instituted a "Wait List" for your borrowers. If the book or DVD they're borrowing is not available, they will be put on the "waitlist". Note that for everyone's title, there could only be ONE borrower on the "waitlist" at a time.
Being new to your library, you must devise a system for Jane and Peter to follow so that:
i) Jane can check the "waitlist" when someone is borrowing
ii) Peter can update the "waitlist" when a book is returned
iii) If the book recently returned is immediately borrowed on the same day, Jane should be able to come to Peter to get the book and update the "waitlist" herself. Otherwise, Peter, at the end of the day, should put it back on the shelf.
iv) Jane and Peter can generate a report summarizing the titles borrowed and returned that day.
The key here is Jane and Peter should be synchronized in what they are going to do. Device a solution (an algorithm, pen-and-paper approach, or series of steps) to enable this new process. Software is not a solution (ie - use an SQL database or a third-party program). Apply methodologies such as test-and-set, Wait-and-signal, and semaphores to assist you in synchronization.
In: Computer Science
1.a. RISC-V has several addressing modes. Describe 4 addressing modes. For each, describe what it does and give an example assembly instruction that uses that addressing mode. b. Starting with a C source code file, describe the steps that must occur in order to actually begin executing the program on your computer.
In: Computer Science
provide a hypothetical situation involving “dirty data” and discuss how data pre-processing would address this issue
In: Computer Science
Represent the decision making involved in the operation of
the
following wash-machine by means of a decision table:
The machine waits for the start switch to be pressed. After the
user
presses the start switch, the machine fills the wash tub with
either hot
or cold water depending upon the setting of the HotWash switch.
The
water filling continues until the high level is sensed. The machine
starts
the agitation motor and continues agitating the wash tub until
either the
preset timer expires or the user presses the stop switch. After
the
agitation stops, the machine waits for the user to press the
startDrying switch. After the user presses the startDrying
switch,
the machine starts the hot air blower and continues blowing hot air
into
the drying chamber until either the user presses the stop switch or
the
preset timer expires.
In: Computer Science
Snakes and ladders is an ancient south Asian board game. It
consists of 10X10 grid board which
contains some snakes and ladders at specific boxes/indexes. One
hundred is the maximum and a must
to win score for each player. First player reaching 100 gets to win
the game and is immediately
declared as first Winner.
You are required to do the following:
Create a snake board of 10 rows and 10 columns.
Randomly generate 09 snakes on the board. In order to generate
snake you only need to know
head and tail of the snake. Make sure that both head and tail are
on the board. Moreover, if
head is on row (Mi) and tail is on row (Mj) then i will always be
less than j.
Similarly, generate 09 ladders on the board.
Print the snake board along with snakes and ladders on the
screen.
In order to start both the player need a six on the dice. Once
the game is started display the
output on the dice and wait for key press (you can use getch())
before second player’s turn.
Game will go on until one player wins the game.
In case player lands on a snake’s head it will come down to its
tail, here you need to display a
message “oops, snake got you!!!”
In case player lands on the bottom of the leader it will climb
the ladder, here you need to
display a message “you got lucky”
Note: Input validation is mandatory when reading taking input size
of the board.
In: Computer Science
Assignment 3C: Answer the following questions
Question 1.
a. Declare a 32-bit signed integer variable and initialize it with the smallest possible negative decimal value.
b. Declare an uninitialized array of 100 16-bit unsigned integers.
c. Declare a string variable containing the word “DVC” repeated 20 times, and terminated with the null char.
Question 2
For the following declarations, assuming that the address of I is 404000h
What are the addresses of J, K, and L?
What is the total number of allocated bytes?
Show the content of the individual bytes allocated in memory in hexadecimal
.DATA
I SBYTE 1, -1
J SWORD 10FFh, -256
K DWORD 23456h
L BYTE 'DVC'
Question 3
Given the following definitions:
.DATA
wval LABEL WORD
barray BYTE 10h, 20h, 30h, 6 DUP (0Ah)
ALIGN 4
warray WORD 5 DUP (1000h)
pressKey EQU <"Press any key to continue ...", 0>
darray DWORD 5 DUP (56789ABh), 7 DUP (12345678h)
dval LABEL DWORD
prompt BYTE pressKey
What will be the value of EAX, AX, and AL after executing each of the following instructions? Assume that the address of barray is 404000h.
a. mov eax, TYPE warray
b. mov eax, LENGTHOF barray
c. mov eax, SIZEOF darray
d. mov eax, OFFSET warray
e. mov eax, OFFSET darray
f. mov eax, OFFSET prompt
g. mov eax, DWORD PTR barray
h. mov al, BYTE PTR darray
i. mov ax, wval
j. mov eax, dval
In: Computer Science
The population growth for Norway is:
1 birth every 1 minutes and 40 seconds
1 death every 3 minutes and 16 seconds
1 arrival every 57 seconds
1 departure every 1 minute and 49 seconds
Assume the current population is 35,201,142. Write a program that calculates the population n minutes from now. Declare a final integer called minutesElapsed and perform your calculations based on that
In: Computer Science
Hello, I am attempting to write a program which calculates the amount of fence pieces needed to achieve a certain distance. The program should take in the amount of fencing needed from the user, then ask them the size of the smaller piece. The fencing is to be made up of two sizes of fencing, the smaller being two feet less than the larger. Then, the program will tell the user how many of each piece is needed. However, I am having trouble understanding how the calculation should be performed. The assignment gives examples, so any help interpreting it would be appreciated.
A user enters that they need 50 feet of fencing and the smaller piece must be 3 feet. The program determines that the larger panel will be 5 feet. Then, the program determines that 6 3-foot pieces and 6 5-foot pieces are needed, plus an additional 2-foot piece.
A user enters that they need 50 feet of fencing and the smaller piece must be 4 feet. The program determines that the larger panel will be 6 feet. Then, the program determines that 5 4-foot pieces and 5 6-foot pieces are needed.
A user enters that they need 2 feet of fencing and the smaller piece must be 1 feet. The program determines that the larger panel will be 3 feet. Then, the program determines that 2 1-foot pieces and 0 3-foot pieces are needed.
A user enters that they need 52 feet of fencing and the smaller piece must be 3 feet. The program determines that the larger panel will be 5 feet. Then, the program determines that 7 3-foot pieces and 6 5-foot pieces are needed, plus an additional 1-foot piece.
Thank you!
In: Computer Science