#include
#include
#include
int main(void) {
int feof(FILE *stdin);
int i, num;
int binary[10];
char input[10];
printf("Starting the CPSC 1011 Decimal to Binary
Converter!\n");
while(1) {
i=0;
printf("\nPlease enter a positive whole number (or EOF
to quit): ");
scanf("%s", input); // user inputs value as a string
for separate values
if(strcmp(input,"")==0) {
printf("\n\tThank you for using the
CPSC 1011 Decimal to Binary Generator.\nGoodbye!\n\n");
return(0);
}
num=atoi(input);
if (num<=0) {
printf("\n\tSorry, that was not a positive whole
number.\n"); // default when num is not positive
}
else {
int temp = num;
while (num>0) {
binary[i] = num % 2; // stores
remainder
num = num / 2; //finds base
i++;
}
printf("\n\t%d (base-10) is equivalent to ",
temp);
for(int j=i-1; j>=0; j--) {
printf("%d", binary[j]); // prints
out binary
}
printf(" (base-2)!\n");
}
}
return(0);
}
ok so i can't use strcmp because it creates a sigpipe error
and i was just wondering how i could implement EOF (crtl+d) to
trigger that end output instead of the strcmp
In: Computer Science
Click cell C9 and insert a VLOOKUP function that looks up the code in cell B9, compares it to the codes and types of art in the range B2:C6, and returns the type of art. Copy the function in cell C9 to the range C9:C54. Hide column B that contains the codes. |
Click cell K9 and insert an IF function that determines if the Issue Price is equal to the Current Value. If the values are the same, display Same as Issue (using the cell reference K2); otherwise, display Increased in Value (using the cell reference K3). Copy the function from cell K9 to the range K10:K54. |
In: Computer Science
Develop a program using python to demonstrate data exchange using USB protocol.
In: Computer Science
How to use Bluetooth to exchange Data between 2 computers. Develop a program with Python to demonstrate this data exchange.
In: Computer Science
design a program that lets the user enter the total rainfall for each of 12 months into an array. The program should calculate and display the total rainfall for the year, the average monthly rainfall, and the months with the highest and lowest amounts.
---->>> Enhance the program so it sorts the array in ascending order and displays the values it contains.
You can choose which sorting algorithm to use (bubble sort, selection sort, or insertion sort). Depending on your choice, you must implement one of the following functions:
def bubble_sort(months, months_len)
def selection_sort(months, months_len)
def insertion_sort(months, months_len)
Example Run
Please enter the rainfall for month [ January ]
15.5
Please enter the rainfall for month [ February ]
17.2
Please enter the rainfall for month [ March ]
18.0
Please enter the rainfall for month [ April ]
22.2
Please enter the rainfall for month [ May ]
15.9
Please enter the rainfall for month [ June ]
2.2
Please enter the rainfall for month [ July ]
0
Please enter the rainfall for month [ August ]
0
Please enter the rainfall for month [ September ]
2.1
Please enter the rainfall for month [ October ]
8.5
Please enter the rainfall for month [ November ]
12.0
Please enter the rainfall for month [ December ]
15.5
Total Rainfall: 129.10000000000002
Average Monthly Rainfall: 10.758333333333335
Month with highest rainfall: April
Month with lowest_rainfall: July
Monthly Rainfall Sorted (ascending):
0 inches
0 inches
2.1 inches
2.2 inches
8.5 inches
12.0 inches
15.5 inches
15.5 inches
15.9 inches
17.2 inches
18.0 inches
22.2 inches
_____________________________________________________________________________________________________________
MONTH_NAMES = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
NUMBER_OF_MONTHS = 12
def get_total_rainfall(months, months_len):
"""
Module Name: get_total_rainfall
Parameters: int [] -> months: an array of integers representing the rainfall in each month
int -> months_len: the length of the 'months' parameter array
Description: Iterates over the array and calculates the total rainfall
"""
# Python Shortcut:
#total_rainfall = sum(months)
total_rainfall = 0
# Iterate of the array of months to accumulate the total.
for index in range(0, months_len):
total_rainfall += months[index]
return total_rainfall
def get_average_monthly_rainfall(months, months_len):
"""
Module Name: get_average_monthly_rainfall
Parameters: int [] -> months: an array of integers representing the rainfall in each month
int -> months_len: the length of the 'months' parameter array
Description: Calculates and returns the average monthly rainfall based on the 'months' array
"""
# Average is calculated by dividing the total by the number of elements.
return get_total_rainfall(months, months_len) / months_len
def get_month_with_highest_rainfall(months, months_len):
"""
Module Name: get_month_with_highest_rainfall
Parameters: int [] -> months: an array of integers representing the rainfall in each month
int -> months_len: the length of the 'months' parameter array
Description: Finds and returns the month with the highest rainfall.
Returns the first month if more than one month qualify as 'highest'
"""
# Sequentially search the array to find the maximum
max_index = 0
for index in range(1, months_len):
if months[max_index] < months[index]:
max_index = index
return max_index
def get_month_with_lowest_rainfall(months, months_len):
"""
Module Name: get_month_with_highest_rainfall
Parameters: int [] -> months: an array of integers representing the rainfall in each month
int -> months_len: the length of the 'months' parameter array
Description: Finds and returns the month with the lowest rainfall.
Returns the first month if more than one month qualify as 'lowest'
"""
# Sequentially search the array to find the minimum
min_index = 0
for index in range(1, months_len):
if months[min_index] > months[index]:
min_index = index
return min_index
def main():
"""
Module Name: main
Parameters: None
Description: Program entry point. Provides the program flow of execution
"""
months = [0.0] * NUMBER_OF_MONTHS
# Input
# Prompt the user to collect the rainfall for each month of the year
for index in range(0, NUMBER_OF_MONTHS):
print("Please enter the rainfall for month [", MONTH_NAMES[index], "]")
rainfall = float(input())
months[index] = rainfall
# Processing
# Calculate the attributes per the assignment
total_rainfall = get_total_rainfall(months, NUMBER_OF_MONTHS)
average_rainfall = get_average_monthly_rainfall(months, NUMBER_OF_MONTHS)
highest_rainfall_index = get_month_with_highest_rainfall(months, NUMBER_OF_MONTHS)
lowest_rainfall_index = get_month_with_lowest_rainfall(months, NUMBER_OF_MONTHS)
# Output
# Display the results
print("Total Rainfall: ", total_rainfall)
print("Average Monthly Rainfall: ", average_rainfall)
print("Month with highest rainfall:", MONTH_NAMES[highest_rainfall_index])
print("Month with lowest_rainfall:", MONTH_NAMES[lowest_rainfall_index])
main()
##Wondering if you can show all 3 sort methods
##thank you!
In: Computer Science
The dictionary is the most natural data structure to hold the apple information from the previous lesson. Below are the parallel arrays that track a different attribute of the apples (note that the above chart (Sweet-Tart Chart) doesn't align with the data from the previous lesson):
names = ["McIntosh", "Red Delicious", "Fuji", "Gala", "Ambrosia", "Honeycrisp", "Granny Smith"]
sweetness = [3, 5, 8, 6, 7, 7.5, 1]
tartness = [7, 1, 3, 1, 1, 8, 10]
Step 1: Data Model (parallel arrays to dictionary)
Build a dictionary named apples. The apple dictionary keys will be the names of the apples. The values will be another dictionary. This value dictionary will have two keys: "sweetness" and "tartness". The values for those keys will be the respective values from the sweetness and tartness lists given above. You will build this by defining a variable named apples (see the complex_map example).
Step 2: Apple Aid
Now that we have our model, create a function named by_sweetness whose parameter will be a tuple (from apples.items()) The function by_sweetness will return the sweetness value of the incoming tuple. This helper function cannot reference the global variable apples (from step 1).
Step 3: Apple Sorting
Write a function called apple_sorting that has two parameters: data (the data model) and sort_helper (the function used to sort the model). The apple_sorting should use the sorted function to sort the data (e.g. data.items()) with sort_helper. The function returns a list of tuples in order of their sweetness (sweetest apples listed first).
Once done, this should work:
print(apple_sorting(apples, by_sweetness))
In: Computer Science
c#
In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user for the number of interior and exterior murals scheduled to be painted during the next month by Marshall’s Murals.
Next, the programs compute the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. The application also displays the total expected revenue and a statement that indicates whether more interior murals are scheduled than exterior ones.
Now, modify the application to accept a numeric value for the month being scheduled and to modify the pricing as follows:
Because of uncertain weather conditions, exterior murals cannot be painted in December through February, so change the number of exterior murals to 0 for those months.
Marshall prefers to paint exterior murals in April, May, September, and October. To encourage business, he charges only $699 for an exterior mural during those months. Murals in other months continue to cost $750.
Marshall prefers to paint interior murals in July and August, so he charges only $450 for an interior mural during those months. Murals in other months continue to cost $500
using System;
using static System.Console;
class MarshallsRevenue
{
static void Main()
{
const int INTERIOR_PRICE = 500;
const int EXTERIOR_PRICE = 750;
string entryString;
int numInterior;
int numExterior;
int revenueInterior;
int revenueExterior;
int total;
bool isInteriorGreater;
Write("Enter number of interior murals scheduled >> ");
entryString = ReadLine();
numInterior = Convert.ToInt32(entryString);
Write("Enter number of exterior murals scheduled >> ");
entryString = ReadLine();
numExterior = Convert.ToInt32(entryString);
revenueInterior = numInterior * INTERIOR_PRICE;
revenueExterior = numExterior * EXTERIOR_PRICE;
total = revenueInterior + revenueExterior;
isInteriorGreater = numInterior > numExterior;
WriteLine("{0} interior murals are scheduled at {1} each for a
total of {2}",
numInterior, INTERIOR_PRICE.ToString("C"),
revenueInterior.ToString("C"));
WriteLine("{0} exterior murals are scheduled at {1} each for a
total of {2}",
numExterior, EXTERIOR_PRICE.ToString("C"),
revenueExterior.ToString("C"));
WriteLine("Total revenue expected is {0}",
total.ToString("C"));
WriteLine("It is {0} that there are more interior murals scheduled
than exterior ones.", isInteriorGreater);
}
}
In: Computer Science
What does it mean if synchronous FIFO has features of
- Data are 5-bit words
- FIFO depth: 3 positions
In: Computer Science
1. Create a Word document in the Documents library. Write a small “summary or review” of an interesting “technology article” – The topics can be anything related to recent news in technology “Example: Launching of new gadgets of Apple, or Artificial Intelligence and its uses, Amazon Web Services etc” please include workcited
In: Computer Science
Problem
General Statement: Read in a letter and a number. The number indicates how big the letter triangle should be. The number indicating the size of the triangle will have a range from 0 to 250. num>=0 and num<=250
Input: The first number indicates the number of data sets to follow. Each data set will contain one letter and one number. All letter input will be uppercase.
Data File : pr36.dat
Output: Output the letter triangle specified.
Helpful Hints / Assumptions: The letters must wrap around from Z to A. If you start with Z and have to print 5 levels, you must wrap around and start with A after the Z level is complete.
Sample Input :
3
5 A
3 Z
4 C
Sample Output :
A
BB
CCC
DDDD
EEEEE
Z
AA
BBB
C
DD
EEE
FFFF
In: Computer Science
You've devised a new twist on the traditional 'What number am I thinking of?' game to help your cousins learn their 7 times tables! Write a game that asks the user to guess the number you are thinking of. (For this game, the number will always be 42.)
The user is allowed 10 guesses, and makes a 'Mistake!' if they guess a number that isn't a multiple of 7. A user can make a maximum of one mistake, otherwise they lose the game. When the game is over, you should always print out That was fun.
Here is an example:
Guess a multiple of 7: 14
Nope!
Guess a multiple of 7: 32
Mistake! That number isn't a multiple of 7.
Guess a multiple of 7: 28
Nope!
Guess a multiple of 7: 86
Another mistake. Too bad.
That was fun.
Here is another example:
Guess a multiple of 7: 7
Nope!
Guess a multiple of 7: 14
Nope!
Guess a multiple of 7: 126
Nope!
Guess a multiple of 7: 133
Nope!
Guess a multiple of 7: 70
Nope!
Guess a multiple of 7: 77
Nope!
Guess a multiple of 7: 63
Nope!
Guess a multiple of 7: 35
Nope!
Guess a multiple of 7: 126
Nope!
Guess a multiple of 7: 77
Nope!
No guesses left!
That was fun.
If the user correctly enters 42, your program should print out You won! instead of Nope!, and then not ask for any more guesses. For example:
Guess a multiple of 7: 42
You won!
That was fun.
In: Computer Science
Design and implement a relational database application of your choice using MS Workbench on
MySQL
a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits
of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both
relations (tables); (15%)
b) Based on your expected use of the database, choose some of the attributes of each relation as
your primary keys (indexes). To each Primary Key name, add the last 4 digits of your Student-
ID by using Alter command. Explain why you choose them as the primary keys; (10%)
c) Specify one Update, one Delete, one Select, one Join, and one View in SQL that are needed by
your database application
In: Computer Science
CSCE 3600: Systems Programming
Recitation Assignment 3 – Sed and Gawk
Due: 06:00 PM on Monday October 12 2020
DESCRIPTION: In this recitation assignment, you will just practice to run sed and gawk commands and record your work session into a file. In other words, just type and run commands specified in bold Consolas (except $ sign :) below on your terminal.
Let’s start. First, open a terminal (bash) session. Issue the first command
$ script FirsName_LastName_04.txt
where FirsName_LastName_04.txt is a file name with FirstName_LastName replaced with your real names. That command will start recording of your work into that file.
The sed commands: go to one of your directories that contains plenty of files (more than 10)
$ cd name-of-directory-with-more-than-10-files
and then in that directory create a list of files by issuing the following command
$ ls –l > sedfile.txt
Print 5 lines of sedfile.txt file to the terminal using statement
$ sed –n 1,5p sedfile.txt
Replace the first “-“character on lines in the file with “R”
$ sed –i "s/^-/R/g" sedfile.txt
-i option instructs sed to replace the original file with output file it creates.
Print 5 lines of sedfile.txt file again to see what was changed
$ sed –n 1,5p sedfile.txt
Delete the first line in the file
$ sed –i 1d sedfile.txt
Find some pattern on one of the lines in the file (like name, date, or memory size) and issue the following command to add new line after that pattern.
$ sed –i '/YOUR PATTERN/a This will be added as new line'
Print out the first 10 lines of your sedfile.txt file again to verify that these changes (deleting the first line and adding a new line) worked:
$ sed –n 1,10p sedfile.txt
Now let’s work with gawk. Create a list of running processes on your system by issuing the following command from your command prompt as follows:
$ ps –ef > gawkfile.txt
Print gawkfile.txt using the NR system variable as follows:
$ gawk 'NR <= 10' gawkfile.txt
This should display the first 10 lines of your gawkfile.txt file. Processes will be covered in detail a little later on in this course. So how many processes are running on your system?
$ gawk 'END {print NR}' gawkfile.txt
Since our gawkfile.txt file contains a header with the fields, we should have 1 less process running on our system. Let’s try to print out only those processes that only you are running. This means that we want to print out some fields where the UID is your user ID. If you do not know your user ID, you can issue the whoami command at your command prompt to find out.
$ gawk '/YOUR USER ID/{print NR, $0}' gawkfile.txt
Let’s see what is result of matching on the first field ($1)?
$ gawk '$1 ~ /YOUR USER ID/{print NR, $0}' gawkfile.txt
That ensures that only the processes that you own are printed!
We see that the first line of gawkfile.txt contains a header with most likely 8 fields (i.e., UID, PID, PPID, C, STIME, TTY, TIME, and CMD, though there might be some variation in different Linux distributions). However, because we use the default field separator of whitespace, some records might contain more fields. So, let’s print out those records that have more than 8 fields. We use here gawk variables NR and NF.
$ gawk 'NF > 8 {print NR, NF}' gawkfile.txt
Now, we print only fields from 9th to max (NF) on line if line contains more than 8 fields.
$ gawk 'NF>8 {for(i=9; i<=NF; i++) print NR, NF, $i}' gawkfile.txt
Now, we swap the PID (field $2) and PPID (field $3) columns so that each record lists the parents’ process ID first by just printing field in the specified order below (3 before 2).
$ gawk 'BEGIN {OFS="\t"};{print $1,$3,$2,$4,$5,$6,$7,$8}' gawkfile.txt
OFS above is Output Field Separator, so fields in output should be separated by a Tab.
To output result of gawk command to a file instead of terminal you can use redirection
$ gawk 'BEGIN {OFS="\t"};{print $1,$2,$3,$5}' gawkfile.txt > out
Let’s finish your recording session and close your script file
$ exit
You should see now FirsName_LastName_04.txt in the current directory.
REQUIREMENTS: Your typescript file will be graded based largely on whether you completed the work correctly, so you should make sure you obtained meaningful results from each command. • Although this assignment is to be submitted individually (i.e., each student will submit his/her own source code), you may receive assistance from your TA, IA (i.e., Grader), and even other classmates. Please remember that you are ultimately responsible for learning and comprehending this material as the recitation assignments are given in preparation for the minor assignments, which must be completed individually.
SUBMISSION: You will electronically submit your typescript file FirsName_LastName_04.txt to the Recitation 3 drop box in Canvas by the due date and time. No late recitation assignments will be accepted.
In: Computer Science
Read the articles from the external sources listed below.
External Sources:
The 5 Types Of Organizational Structures: Part 1, The Hierarchy (Links to an external site.)
The 5 Types Of Organizational Structures: Part 2, 'Flatter' Organizations (Links to an external site.)
The 5 Types Of Organizational Structures: Part 3, Flat Organizations (Links to an external site.)
The 5 Types Of Organizational Structures: Part 4, Flatarchies (Links to an external site.)
The 5 Types Of Organizational Structures: Part 5, Holacratic Organizations (Links to an external site.)
In a post of no less than 150 words, provide an explanation of why you feel that a proper organizational structure is a necessity in ensuring a successful organization. Also, provide a compare/contrast of at least two types of organizational structures and your opinion on which one would be more beneficial. Here are two examples of two different, well-known companies organizational structures.
Participation is mandatory, so be sure to respond to at least 2 of your classmates' posts giving constructive feedback and suggestions. This discussions purpose is to aid your classmates in refining their concept.
In: Computer Science
If the current number is divisible by 2, then print HAP
If the current number is divisible by 5, then print PY
If the current number is divisible by both 2 and 5, then print HAPPY
If the number is neither divisible by 2 nor 5, then print the number
Example: 1 HAP 3 HAP PY HAP 7 HAP 9 HAPPY 11 HAP 13 HAP PY HAP 17 HAP 19 HAPPY …
In: Computer Science