Write a java code to demonstrate the File IO.
Your code should get the following information from the user.
• Get a file name fname for output
• Get number of data (numbers) (N) you want to process from the user
• Get N numbers from the users through keyboard and store them in an array
• Get M (How many numbers to read from file)
• (Or)You are free to use same N for M (use N for both purposes)
You have to define two methods:
1) To write the numbers from the array into the file fname
2) To read numbers from the file fname, store them in an array, and compute average of the numbers. The method should display the numbers from the array and the average value.
In: Computer Science
Given any positive integer n, the hailstone sequence starting at n is obtained as follows. You write a sequence of numbers, one after another. Start by writing n. If n is even, then the next number is n/2. If n is odd, then the next number is 3n + 1. Continue in this way until you write the number 1.
For example, if you start at 7, then the next number is 22 (3 × 7 + 1). The next number after 22 is 11.
The hailstone sequence starting at 7 is [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1] and its length is 17.
The hailstone sequence starting at 6 is [6, 3, 10, 5, 16, 8, 4, 2, 1] and its length is 9.
The hailstone sequence starting at 1 is [1] and its length is 1.
The Assignment
Write and test a C++ program that reads a number n from the standard input (after giving a suitable prompt) and then writes the following information on the standard output:
the entire hailstone sequence starting at n, all on one line, with the numbers separated by spaces;
the length of the hailstone sequence that starts with n;
the largest number in the hailstone sequence that starts with n;
an indication of whether the hailstone sequence that starts with n contains a number that is greater than 1000.
the length of the longest hailstone sequence that starts with a number from 1 to n;
the starting number of the longest hailstone sequence that starts with a number from 1 to n;
the largest number that occurs in any hailstone sequence that starts with a number from 1 to n.
the start value, from 1 to n, of the hailstone sequence that contains largest number reported in the previous step.
For this program, use loops. Do not use recursion. Use type int for all of the integers. Do not use any of
The main function must not contain any loops. You can use the <cstdio>, <iostream> and <algorithm> libraries for this assignment.
The output needs to be sensible and easy to read, not just numbers. It must follow the general template below, with all numeric results lined up (approximately) vertically. Each part of the output should be on a separate line. Parts in black are written by the program.
What number shall I start with? 7 The hailstone sequence starting at 7 is: 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 Sequence length: 17 Largest number: 52 Contains a number >1000? no Greatest length starting with 1 to 7: 17 Start value of sequence of length 17: 7 Largest value in a sequence starting with 1 to 7: 52 Start value of sequence containing 52: 7
In: Computer Science
In this program we are going to utilize multiple classes to demonstrate inheritance and polymorphism. We will be creating a base class for our game character. The base class will be LifeForm. We will have derived classes of Human, Dragon, and Unicorn.
LifeForm will have the following attributes:
You will need to provide a default constructor that initializes these attributes as follows:
You will need to provide a getter and setter for each of these variables. When the attribute has a range, the setter method should not allow a value outside that range. For example, if the setHitPoints(points) is called with points = -1, the attribute should NOT be changed. The variables should be private. Please provide a toString method which will return a String containing the values in these variables.
In your Human, Dragon and Unicorn classes you will need variables to hold the character name, weapon, and magic values. Values will be as follow:
Weapon |
Magic Amount |
|
Human |
Sword or Dagger |
0-50 |
Dragon |
Fire or Ice |
0-100 |
Unicorn |
Horn or Charm |
100-500 |
You will need to provide getters and setters for each of these private variables. Again, they should not allow values not in the table. You also need to provide a constructor for all of the variables, both the ones in the derived class and the ones in the base class.
Please provide a toString method that returns the type of character, the name, the weapon, the magic amount and the values from base class, call the toString() from the base class.
Create a driver class that allows the user to create a random set of characters. These should be of type Human, Dragon and Unicorn. These should be stored in an ArrayList of LIfeForm. You should prompt the user for entries and create three characters of each class type and store them in the ArrayList. Once you have added the three characters. Print the characters from the ArrayList using your toString methods.
Example output: (Italics indicate user input)
Enter Lifeform 1:
Enter Lifeform Type: human
Enter Lifeform Name: Jon Snow
Enter hit points: 10
Enter strength: 5
Enter weapon: sword
Enter magic: 25
Enter Lifeform 2:
Enter Lifeform Type: unicorn
Enter Lifeform Name: Sparkles
Enter hit points: 0
Enter strength: 18
Enter weapon: charm
Enter magic: 300
Enter Lifeform Type: dragon
Enter Lifeform Name: Smaug
Enter hit points: 0
Enter strength: 18
Enter weapon: ice
Enter magic: 99
The available life forms are: ↵
Lifeform [hitPoints=10, strength=5, type=human]Human [name=jon snow, weapon=sword, magic=25]↵
Lifeform [hitPoints=0, strength=18, type=unicorn]Unicorn [name=sparkles, weapon=charm,magic=300]↵
Lifeform [hitPoints=0, strength=18, type=dragon]Dragon [name=smaug, weapon=ice, magic=99]↵
Grading Criteria (total 100 points):
Follows coding standards |
10 |
Properly inputs all data |
20 |
Properly creates minimum of 4 separate files using inheritance correctly |
20 |
Properly creates ArrayList of Lifeform |
15 |
Properly uses polymorphism to call toString from the ArrayList |
20 |
Outputs are neat and easily read |
15 |
In: Computer Science
Extra Credit (0.5 per)
Here is the link w/country codes:
https://www.iban.com/country-codes
In: Computer Science
Write a Java program for slidsender and slidreiver
1. Start the program
2. Get the frame size from the user
3. To create the frame based on the user
4. To send frames to server from the client
5. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to
6. Stop the program
In: Computer Science
You want to test two different web page layouts to see which one performs better (this is known as an A/B test).
In: Computer Science
Complete the attached code so that if the user enters the number 22 for the number of items purchased and 10.98 for the price of each, the following results are displayed:
The total bill is $241.56
Hint: It must include cin and variables.
// This program will read the quantity of an item and its price
// Then print the total price.
// The input will come from the keyboard and the output will go to the monitor.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int quantity; // number of item purchased
float itemprice; // price of every article
float totalbill; // total account
cout << setprecision(2) << fixed << showpoint;
cout << “please, enter number of items purchased” << endl;
// indicate the instruction to record the amount
// indicate the instruction to ask the price
// indicate the instruction to record the price of each item
// indicate the assignment instruction to determine the total account
// indicate the instruction to show the total on the monitor
return 0;
}
In: Computer Science
write c program to generate 6 numbers to simulate rolling of a dice . use while loop to run 100 and 10000 times. print out how many times it generates 1, 2,3,4,5,6.
In: Computer Science
network security tool- Nmap
• Platform and tools used
• Design of experiments (attack/defense)
• Preliminary tests
• IEEE style report
In: Computer Science
Evaluate possible benefits and drawbacks of using wireless solutions. Propose at least two alternatives for wireless communications in the network
In: Computer Science
How is the emergence of the Internet of Things (IoT) impacting business processes for firms? Give specific examples to illustrate your point(s). Please answer in 2-3 paragraphs
In: Computer Science
Consider the following C++ program that makes use of many
features that are unique to C++ and did not
exist in C.
#include <iostream>
#include <string>
#include <cstdint>
#include <vector>
using namespace std;
enum LetterGrade {
A = 4,
B = 3,
C = 2,
D = 1,
F = 0
};
// type T must be castable into a double
template<class T>
double getArrayAverage(vector<T>& vec) {
double sum = 0;
for (const auto& value : vec) {
sum += static_cast<double>(value);
}
const auto avg = sum / vec.size();
return avg;
}
void convertCharToLetterGrade(char& grade) {
switch (grade) {
case 'A': case 'a':
grade = 4;
return;
case 'B': case 'b':
grade = 3;
return;
case 'C': case 'c':
grade = 2;
return;
case 'D': case 'd':
grade = 1;
return;
case 'F': case 'f':
grade = 0;
return;
default:
cout << "Warning... Invalid Character... Recording an
F.\n";
return;
}
}
LetterGrade getLetterGradeFromAverage(const double avg) {
if (avg >= 90)
return LetterGrade::A;
else if (avg >= 80)
return LetterGrade::B;
else if (avg >= 70)
return LetterGrade::C;
else if (avg >= 60)
return LetterGrade::D;
else
return LetterGrade::F;
}
int main()
{
string firstName;
cout << "Please enter your first name: ";
cin >> firstName;
string lastName;
cout << "Please enter your last name: ";
cin >> lastName;
int32_t numPrevCourses;
cout << "Enter number of previous courses: ";
cin >> numPrevCourses;
cin.ignore();
vector<LetterGrade> prevGrades(numPrevCourses);
for (int32_t courseIx = 0; courseIx < numPrevCourses;
++courseIx) {
cout << "Enter letter grade for course " << courseIx
<< ": ";
char letterGrade;
cin.get(letterGrade);
cin.ignore();
convertCharToLetterGrade(letterGrade);
prevGrades.at(courseIx) =
static_cast<LetterGrade>(letterGrade);
}
int32_t numExams;
cout << "Enter number of exams this semester: ";
cin >> numExams;
cin.ignore();
vector<int32_t> examGrades(numExams);
for (int32_t examIx = 0; examIx < numExams; ++examIx) {
cout << "Enter grade for exam " << examIx << " as
an integer: ";
cin >> examGrades.at(examIx) ;
cin.ignore();
}
const auto fullName = firstName + " " + lastName;
cout << "Grade Report For " << fullName <<
":\n";
const auto examAverage = getArrayAverage(examGrades);
cout << "Your exam average is: " << examAverage
<< "\n";
// get GPA with newest course added:
const auto newLetterGrade =
getLetterGradeFromAverage(examAverage);
prevGrades.push_back(newLetterGrade);
const auto gpa = getArrayAverage(prevGrades);
cout << "Your latest GPA is: " << gpa <<
"\n";
return 0;
}
Your Task: Please rewrite this program in pure
C and without any C++ elements. You may use any
compiler that you would like, but your program cannot have any C++
features .
Once you finish writing your program, please write a brief
report (no more than a few paragraphs)
describing features in the above program that are in C++ and not in
C and the different work-arounds you
had to come up with in order to achieve the same functionality.
Please feel free to elaborate on the
aspects of the C program that were difficult to implement.
Please submit your program (as a .c file) as well as your report
(any text format will suffice)
In: Computer Science
It’s not easy
to come up with a secure password that one can actually remember.
One of the
methods proposed is to take a line of text and take first letter of
each word to form
a password. An extra step is substitute ”o” with 0, ”a” with ”@”,
and ”l” with
1. For instance, using ”Come to the meadow on law street” would
yield
”Cttm01s”. Write a program that asks the user to enter a phrase and
outputs
the password that is generated using these rules.
You can assume that the words in the phrase will be separated by a
single space or
a common punctuation sign such as ”.,?!;:” followed by a space.
PYTHON PLEASE! THANK YOU
In: Computer Science
C -Language Create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should prompt the user for the operation they wish to perform followed by the numbers they wish to operate on. You should have a function for each operation and use branches to determine which function to call.
I need this to make any integers given, into decimal numbers, such as 3 to 3.0, or 2 to 2.0, also, so that I can multiply or add things like 2.5 + 3.0 or 2.5 * 2.5, etc.
Thank you, please see my code below.
-------------------------------------------------------------
MY CODE:*****
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
//Functions
int add(int a, int b)
{
return a + b;
}
int sub(int a, int b)
{
return a - b;
}
int mul(int a, int b)
{
return a * b;
}
float div(int a, int b)
{
return a * 1.0 / b;
}
int main()
{
int result, a, b, choice;
float res;
//User prompts
printf("Math Calculator: What type of operation would you like me to use? (You will choose numbers after selection) : \n1.Addition\n2.Subtraction\n3.Multiply\n4.Divide\n");
scanf("%d", &choice);
printf("Enter first number : ");
scanf("%d", &a);
printf("Enter second number : ");
scanf("%d", &b);
//Cases
switch (choice) {
case 1:
result = add(a, b);
printf("The answer equals %d", result);
break;
case 2:
result = sub(a, b);
printf("The answer equals %d", result);
break;
case 3:
result = mul(a, b);
printf("The answer equals %d", result);
break;
case 4:
res = div(a, b);
printf("The answer equals %f", res);
break;
default:
printf("You did not select a valid operation from above.");
break;
}
return 0;
}
In: Computer Science
A palindrome prime is a prime number that reads the same
forwards or backwards. An example of a
palindrome prime is 131. Write a method with the following
signature for determining if a given
number is a palindrome prime.
public static boolean isPallyPrime(int nVal)
Note: For this assignment you are not allowed to use the
built in Java class Array as part of your solution for any of these
questions. Your Method signatures must
be the same as given here.
In: Computer Science