C++ Write a function called gen_dates() that generates random dates. It takes two arrays of integers called months and days to store the month and day of each date generated, a constant array of 12 integers called num_of_days that specify the number of days of each of the 12 months and an integer called size that specifies how many dates to generate and randomly generates size dates, storing the generated months in months array and generated days in days array. The function must generate only valid dates. To do that, it sets the upper limit of the days to generate to the values given in num_of_days array that is passed as a parameter. The number of days for the 12 months stored in num_of_days array are as follows: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Write another function called search_date() that takes two arrays of integers called months and days, an integer for size (same as above) and two more integers for the month and day to search for within the two arrays of months and days. The function returns the index of the found date if found and -1 if not found.
In main, declare two arrays of integers of maximum size 50, called months and days, to hold the generated months and days. Also declare an array of integers called num_of_days and initiaize it to the number of days of each of the 12 months. Because February can have either 28 or 29 days, depending on if the year is a leap year or not, the program must ask the user to enter the current year (in main). If it's a leap year, the number of days for month 2 (February) must be set to 29, otherwise, it's set to 28. A year is a leap year if it's either divisible by 400 or if it's divisible by 4, but not by 100.
The program must also ask the user (in main) how many random dates to generate (size). Then, it must pass the months and days arrays, the num_of_days array and size to gen_dates() function and print the generated dates (in main).
Then, read a single date such as 9/21 and pass the two arrays, the size and the month and day to search for to search_date() function. If the specified date was found, print the index of the first date found in main or print in main that the date could not be found.
All user input must be read in main and generated dates printed in main. Do not use any global variables. The two specified functions must receive only specified parameters. The gen_date() function returns nothing and search_date() function returns the index of found date or -1. ?
In: Computer Science
**Java Programming Question**
A class that implements a data type, “Point,” which has the following constructor:
Point(double x, double y, double z)
A sample run would be as follows.
>java Point 2.1 3.0 3.5 4 5.2 3.5
The first point is (2.1,3.0,3.5)
The second point is (4.0,5.2,3.5)
Their Euclidean distance is 2.90
**Java Programming Question**
In: Computer Science
programming language is c#.
Create a method that prompts a user of your console application to
input the information for a student:
static void GetStudentInfo()
{
Console.WriteLine("Enter the student's first name: ");
string firstName = Console.ReadLine();
Console.WriteLine("Enter the student's last name");
string lastName = Console.ReadLine();
// Code to finish getting the rest of the student data
.....
}
static void PrintStudentDetails(string first, string last,
string birthday)
{
Console.WriteLine("{0} {1} was born on: {2}", first, last,
birthday);
}
1. Using the above partial code sample, complete the method for
getting student data.
2. Create a method to get information for a teacher, a course, and
program, and a degree using a
similar method as above.
3. Create methods to print the information to the screen for each
object such as static
void PrintStudentDetails(...).
4. Just enter enough information to show you understand how to use
methods. (At least three
attributes each).
5. Call the Get methods from the Main method in the
application.
6. Call the Print methods from within each Get method.
Exceptions
1. At times, developers create method signatures early on in the
development process but leave the
implementation until later. This can lead to methods that are not
complete if a developer forgets
about these empty methods. One way to help overcome the issue of
not remembering to complete
a method is to throw an exception in that method if no
implementation details are present.
2. For this task, use MSDN to research the NotImplementedException
exception.
3. Create a new method for validating a student's birthday. You
won't write any validation code in this
method, but you will throw the NotImplementedException in this
method.
4. Call the method from Main() to verify your exception is
thrown.
Challenge
Using MSDN, research the System.DateTime type. Using the
information you learn, modify your birth
date field for the student and/or teacher to ensure it used a
DateTime type if you did not already
include that in your data for these objects.
• Remove your NotImplementedException statement in the validate
method you created above.
• Create a try/catch block to catch invalid date entries and
display a message to the user if this
occurs. (Console output)
• Assume that your student must be at least 18 years of age to
enroll at a university.
• Write code that validates the student is at least 18 years old.
You can use birth year and math or
you can calcuate from today's date and work back.
• Output an error message to the console window if the student's
age is less than 18
In: Computer Science
Consider this set A = { a, b, c, d } and the following relations
R6 = { ( a, a ), ( a, b), ( b, b), ( c, d ) }
R7 = { ( a, a), ( b, b ), ( b, c ), ( c, c ), ( c, d), (d, d) }
R8 = { (a, b), (a, d), ( b, a), ( d, a) , ( b, d) , (d, b) }
R9 = { ( a, a), ( b, c) }
R10 = { ( a, b), (b, d), (a, d), ( a, a ) , (b, b), (b, d) }
5. Which of the above relations are reflexive and state why ?
6. Which of the above relations are symmetric and state why ?
7. Which of the above relations are transitive and state why ?
In: Computer Science
There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in 1st grade focus on addition. They are required to memorize their addition facts from 1 to 12.
Create a function that prompts the user to enter a number between 1 and 12. Then display - using the input supplied - the addition and subtraction math facts for that number from 1 to 12 for the number entered. The output should be the results of the mathematical calculations.
See below example below:
The user enters "5" as their input. Below is the expected output.
Addition Math Facts for "5"
5 + 1 = 6
5 +2 = 7
...
5 + 11 = 16
5 + 12 = 17
Subtraction Math Facts for "5"
12 - 5 =
11 - 5 =
10 - 5 =
...
7 - 5 = 2
6 - 5 = 1
5 - 5 = 0
* Please note the subtraction facts should stop at the input number - the input number because 1st graders are not prepared to learn about negative numbers.
If the user enters a number not between 1 and 12, open an alert window stating that it is an invalid number, and prompt them to enter a number again meeting the criteria. Finally, if the number entered is bellow 6, make the background color blue and the text white, if the number is above 6 make the background color red and the text yellow, and if the number is six then make the background color white and the text black.
* Should be in HTML language.
HINT: use a variable and a window.prompt() to store what the person enters, a conditional statement, and string concatenation using HTML as we discussed in class.
In: Computer Science
Information security is achieved through a combination of what three entities? Provide at least one example of each entity.
In: Computer Science
1)Given a list L1, create a list L2 that contains all but the last element of L1 (e.g. if L1 is ["a","z",True], L2 should be equal to ["a","z"]
2)Given a string s, assign a variable has_z that is True if s contains the letter "z" anywhere within it.
3)Write Python code that calculates the mean of a given list of numbers x and saves the result in a variable m.
4)Given two numeric variables, x and y, assign the maximum of x and y to a variable m.
5)given a string s, write Python code that sets a boolean variable has_two_caps to True if the string contains exactly two capital letters (use the .isupper() string method to test individual letters) and False otherwise.
6)Given two variables x and y containing numerical values and a boolean variable use_x, assign a third variable z the value of x if use_x is True; assign it the value of y if use_x is False.
7)Given a list of logical values x, set all_x to True if all of the values in x are True, and False otherwise
IN PYTHON!!
In: Computer Science
I am practicing questions to studying with and the prompt is to:
Write statements that assign random integers to the variable n in the following ranges:
This is what I have thus far but when it displays my fourth value that is supposed to be in between 1000 and 1114 is does not confine between those values, am I doing something wrong/is there a way to simplify my work? Looking for a detailed answer with an explanation to really understand this. This is what I have:
<html>
<head>
<meta charset = "utf-8">
<title>Random integers to variable</title>
<style type = "text/css">
p { margin: 0px; }
p.space { margin-top: 10px; }
</style>
<script>
var value1;
for ( var n = 1; n <= 1; ++n )
{
value1 = Math.floor( 1 + Math.random() * 7);
document.writeln( "<p>" + value1 + "</p>" );
}
var value2;
for ( var n = 1; n <= 1; ++n )
{
value2 = Math.floor( 1 + Math.random() * 221);
document.writeln( "<p>" + value2 + "</p>" );
}
var value3;
for ( var n = 1; n <= 1; ++n )
{
value3 = Math.floor( 0 + Math.random() * 49);
document.writeln( "<p>" + value3 + "</p>" );
}
var value4;
for ( var n = 1; n <= 1; ++n )
{
value4 = Math.floor( 1000 + Math.random() * 1114);
document.writeln( "<p>" + value4 + "</p>" );
}
var value5;
for ( var n = 1; n <= 1; ++n )
{
value5 = Math.floor( -2 + Math.random() * 9);
document.writeln( "<p>" + value5 + "</p>" );
}
var value6;
for ( var n = 1; n <= 1; ++n )
{
value6 = Math.floor( -13 + Math.random() * 21);
document.writeln( "<p>" + value6 + "</p>" );
}
</script>
</head>
<body></body>
</html>
In: Computer Science
home / study / engineering / computer science / computer science questions and answers / Using JAVA The Following Code Is Able To Read Integers From A File That Is Called "start.ppm" ...
Your question has been answered
Let us know if you got a helpful answer. Rate this answer
Question: Using JAVA The following code is able to read integers from a file that is called "start.ppm" ont...
Using JAVA
The following code is able to read integers from a file that is called "start.ppm" onto a 3d array called "startImage".
Implement the code by being able to read from another file (make up any file name) and save the data onto another 3d array lets say you call that array "finalImage".
The purpose of this will be to add both arrays and then get the average
Save the average onto a separte 3darray,lets say you call it "middlearray"
Then add startImage and middlearray and get the average then save it to another array called "fourtharray"
Then add finalImage and middle array and get the average then save it to another array called "fiftharray".
Print all 5 arrays
I can not submit data file because there are about 667,000 integers on each file and both files are the same size. The file is from an image that got converted onto a ppm file. I don't really see the purpose in adding the file to this question either way. The code below is already capable of reading from one file. I just need to code that will allow me to read from a different file (lets say we call that file "final.ppm". Please write an individual method for each file that is being read. Then add answer the questions from above.
I have already posted this question 2 times and its been answered by the same person and everytime i run the program it just prints only 0's. If this questinon gets answered by the same person again its OK.
import
java.util.Scanner;
import java.io.*;
public class P1
{
public static void main(String[] args) throws IOException
{
final int ROW=1000;
final int COL=667;
File file= new File("start.ppm");
Scanner inputF= new Scanner(file);
int[][][] startImage= new int[ROW][COL][3];
int row=0, col=0;
int line=1;
while (inputF.hasNext())
{
if(line<=4)
{
inputF.nextLine();
line++;
}
else
{
line+=3;
if (col< COL)
{
startImage[row][col][0]=inputF.nextInt();
startImage[row][col][1]=inputF.nextInt();
startImage[row][col][2]=inputF.nextInt();
col++;
}
else
{
row++;
col=0;
startImage[row][col][0]=inputF.nextInt();
startImage[row][col][1]=inputF.nextInt();
startImage[row][col][2]=inputF.nextInt();
col++;
}
}
}
inputF.close();
for(row=0;row {
for(col=0;col {
for(int color=0;color<3;color++)
{
System.out.println(startImage[row][col][color]);
}
}
}
}
}
In: Computer Science
describe the security principle of simplicity.
In: Computer Science
11. Consider three processes P1, P2, and P3, and all them three are ready to run at time = 0. Each process has two CPU bursts. When its first CPU burst is completed, each process requests a blocking I/O operation on a separate I/O device. When a process starts to receive service for I/O, the OS scheduler selects and dispatches another process available at the ready queue. The CPU scheduling policy is preemptive priority-based scheduling, where a process being running can be preempted at the arrival of a higher priority process (think about how a preemptive SJF preempts a job currently being running). A smaller priority value indicates a higher priority. Assume the system has only one CPU core.
Process Priority 1st CPU burst I/O burst 2nd CPU burst
P1 1 5 20 5
P2 2 5 10 10
P3 3 5 4 5
Draw the Gantt chart for the above system (make sure to highlight process preemption and completion); calculate the average turnaround time and average waiting time – show your work.
In: Computer Science
This is my code for an array using the bubblesort in the function outside of main. My bubblesort is not working correctly , and I was told i'm missing a +j instead of +i in the function for void sorter.Can someone please help me with making my sorter work properly? everything else is fine and runs great. Thank you #include <stdio.h> #include <stdlib.h> #include <time.h> void printer(int *ptr, int length); void randomFill(int *ptr, int length); void sorter(int *ptr, int length); int main(void) { int size =30; int array[size]; int *myPointer; myPointer = array; int i; for(i =0; i<size; i++) { *myPointer = 0; myPointer++; } printf("\nArray before:\n\n"); printer(array, size); randomFill(array, size); printf("\nArray after insert:\n\n"); printer(array, size); sorter(array, size); printf("\nArray after sort:\n\n"); printer(array, size); return 0; } void printer(int *ptr, int length) { int i =0; for(i =0; i<length; ++i) printf("a[%d] = %d\n\n", i, *(ptr + i)); } void randomFill(int *ptr, int length) { srand(time(NULL)); int i; for(i =0; i<length; i++) { *ptr = (rand()% (205-55+1)) + 55; ptr++; } } void sorter(int *ptr, int length) { int i, j, temp; for(i =0; i<length; i++) { for(j = i+1; j<length; j++) { if(*(ptr +i) > *(ptr +j)) { temp = *(ptr + i); *(ptr + i) = *(ptr + j); *(ptr + j) = temp; } } } }
In: Computer Science
What is s after the following? String s = "AbCd"; s.toLowerCase(); |
|||||||||
|
In: Computer Science
Two people play the game of Count 21 by taking turns entering a
1, 2, or 3, which
is added to a running total. The player who adds the value that
makes the total
reach or exceed 21 loses the game. Create a game of Count 21 in
which a player
competes against the computer, and program a strategy that always
allows the
computer to win. On any turn, if the player enters a value other
than 1, 2, or 3,
force the player to reenter the value. Save the game as
Count21.java
In: Computer Science
Show the decimal integer 79 in 8-bit sign magnitude, one's complement, two's complement and excess-127 respectively in the given order, separated by comma.
In: Computer Science