Write a program that defines an animal data type, with an animal name, age, and category (cat, dog, etc.), as well as an animal array type that stores an array of animal pointers. (ex.
structType *arr[size];) Your program will prompt the user to enter the data for as many animals as they wish. It will initialize a dynamically allocated animal structure for each animal, and it will store each animal in an instance of the animal array structure. Your program will then print all the animal information to the screen. You will upload your C program as one file.
In: Computer Science
In: Computer Science
1. Write Python code to -
(a) ask user to enter a list of animals, one item at a time, until
“done” to terminate input
(b) randomly display a selected item from the list, starting with
“I like ______”.
When run, the output should look something like
this:
Enter an item; 'done' when finished: cats
Enter an item; 'done' when finished: dogs
Enter an item; 'done' when finished: guinea pigs
Enter an item; 'done' when finished: done
You are done entering items.
I like guinea pigs
2. Given the following two strings:
str_1 = "the rain! in Spain falls mainly on the plains"
str_2 = "cats don't like dogs and mice. What a day."
Implement logic to produce the following output by manipulating str_1 and str_2.
# Output ---> rain! What a day.
In: Computer Science
Write a program that sorts prices of 10 tacos in ascending order based on the price, using arrays.
Requirements:
Example Output
Welcome to the taco price sorter! Enter 10 taco names and prices and I'll sort it!
Enter the name of taco 1
Crunchy Taco
Enter taco's price
1.19
Enter the name of taco 2
Crunchy Taco Supreme
Enter taco's price
1.59
Enter the name of taco 3
Soft Taco
Enter taco's price
1.19
Enter the name of taco 4
Soft Taco Supreme
Enter taco's price
1.59
Enter the name of taco 5
Chicken Soft Taco
Enter taco's price
1.79
Enter the name of taco 6
Crispy Potato Soft Taco
Enter taco's price
0.99
Enter the name of taco 7
Double Decker Taco
Enter taco's price
1.89
Enter the name of taco 8
Double Decker Taco Supreme
Enter taco's price
2.29
Enter the name of taco 9
Doritos Locos Taco (Nacho Cheese)
Enter taco's price
1.49
Enter the name of taco 10
Doritos Locs Tacos(Fiery) Supreme
Enter taco's price
1.89
Sorted Tacos are
Taco Prices Crispy Potato Soft Taco 0.99
Taco Prices Crunchy Taco 1.19
Taco Prices Soft Taco 1.19
Taco Prices Doritos Locos Taco (Nacho Cheese) 1.49
Taco Prices Crunchy Taco Supreme 1.59
Taco Prices Soft Taco Supreme 1.59
Taco Prices Chicken Soft Taco 1.79
Taco Prices Double Decker Taco 1.89
Taco Prices Doritos Locs Tacos(Fiery) Supreme 1.89
Taco Prices Double Decker Taco Supreme 2.29
In: Computer Science
Consider the problem of multiplying n rectangular matrices discussed in class. Assume, in contrast to what we did in class, that we want to determine the maximum number of scalar multiplications that one might need (that is, compute the maximum of all possible parenthesizations). Formulate precisely an algorithm that determines this value. Then carry out your method on the following product to show what is the worst-possible parenthesization and how many scalar multiplications are required to carry it out: M9,1*M1,9*M9,2*M2,8*M8,4.
In: Computer Science
Create an Java application that uses a class to convert number grades to letter grades and another class for data validation.
Specifications
public void setNumber(int number) public int getNumber()
public String getLetter()
A 88-100
B 80-87
C 67-79
D 60-66
F <60
im having some issue getting the overloading of the three string functions to pass values and validate the required entry validation
public class Console {
// require the user to input a value
public static String getString(String prompt) {
return getString(prompt, false);
}
// check that an input has been entered if not return an error
public static String getString(String prompt, boolean required)
{
String choice = "";
Scanner scanner = new Scanner(System.in);
//repeat until a valid input is entered
while (true) {
System.out.print(prompt);
if (choice.isEmpty() && required == true) {
choice = scanner.next();
if (scanner.hasNext()) {
choice = scanner.next();
System.out.println("Error! y or n. Try again.");
}
} else{
}
scanner.nextLine(); // discard any other data entered on the
line
}
return getString(prompt,"y", "n");
}
// require one of two specified string values.
public static String getString(String prompt, String choiceOne,
String choiceTwo) {
String choice = "";
boolean isValid = false;
Scanner scanner = new Scanner(System.in);
//repeat until a valid input is entered
while (!isValid) {
System.out.print(prompt);
if (scanner.hasNext()) {
choice = scanner.next(); // read user entry
//check if valid input is entered, if yes set isValid to true
if (choice.equalsIgnoreCase(choiceOne) ||
choice.equalsIgnoreCase(choiceTwo)) {
isValid = true;
} else { //else display error message
System.out.println("Error! y or n. Try again.");
}
} else {
System.out.println("Error! y or n. Try again.");
}
scanner.nextLine(); // discard any other data entered on the
line
}
return choice;
}
public static int getInt(String prompt) {
int i = 0;
boolean isValid = false;
Scanner scanner = new Scanner(System.in);
while (!isValid) {
System.out.print(prompt);
if (scanner.hasNextInt()) {
i = scanner.nextInt();
isValid = true;
} else {
System.out.println("Error! Invalid integer. Try again.");
}
scanner.nextLine(); // discard any other data entered on the
line
}
return i;
}
}
import java.util.Scanner;
public class Grade {
private int grade;
Grade() {
grade = 0;
}
Grade(int marks) {
this.grade = marks;
}
public void setNumber(int number) {
this.grade = number;
}
public String getLetter() {
if (grade >= 88) {
return "A";
} else if (grade >= 80) {
return "B";
} else if (grade >= 67) {
return "C";
} else if (grade >= 60) {
return "D";
} else if (grade < 60) {
return "F";
}
return "";
}
public String toString() {
return "Letter Grade : " + getLetter();
}
}
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Welcome to the Letter Grade
Converter");
System.out.println();
String choice = "y";
while (choice.equalsIgnoreCase("y")) {
int myGrade = Console.getInt("Enter numerical grade: ");
Grade grade = new Grade(myGrade);
System.out.println("Letter grade: " + grade.getLetter());
choice = Console.getString("Continue? (y/n):");
}
}
}
In: Computer Science
What is 802.1X enterprise mode and why large firms uses this mode? Which network component will play the role of Authenticator in the wireless settings? How does this extension protect the network?
In: Computer Science
Problem Description: Using Python write a Singly‐Linked List (with only the Head pointer) that supports the following operations: 1. Adding an element at the middle of the list. 2. Removing the middle element of the list (and return the data). 3. Adding an element at a given index. 4. Removing an element at a given index (and return the data). For #1 and #2, ignore the operations if the length of the list is an even number. For #3, if there is already an element at the specified index, it (and everything coming before it) should be shifted left. if the specified index is beyond the existing list, then add the new element at the end of the list. For #4, ignore the operation if there is no item at the specified index. For each of these operations, design appropriate test cases for exhaustively testing the operation, and show the contents of the list before and after executing each test by grouping test case inputoutputs for a given operation to ensure readability.
Note: You have to use the linked list skeleton code provided with this document as a starter code for your solution. You CANNOT use any of the other methods (such as addBefore(), removeAfter(), search(), etc.)
class Node:
"""Node class for a linked list"""
def __init__(self, item=None):
"""constructor for the Node class"""
self._item = item
self._next = None
def __str__(self):
return str(self._item)
class SLL_H:
def __init__(self):
self._head = None
def __str__(self):
"""overloaded function for converting the linked list to a
string"""
str_rep = ""
curr = self._head
str_rep +="Head-> "
while(curr):
str_rep +=str(curr._item)
str_rep +=" -> "
curr = curr._next
str_rep +="None"
return str_rep
In: Computer Science
In Express Sessions (in the context of React), how are session IDs typically verified?
In: Computer Science
C++, Complete this program as directed
// This program will read in a group of test scores (positive
integers from 1 to 100)
// from the keyboard and then calculate and output the average
score
// as well as the highest and lowest score. There will be a maximum
of 100 scores.
// PLACE YOUR NAME HERE
#include <iostream>
using namespace std;
typedef int GradeType[100]; // declares a new data type:
// an integer array of 100 elements
float findAverage (const GradeType, int); // finds average of all
grades
int findHighest (const GradeType, int); // finds highest of all
grades
int findLowest (const GradeType, int); // finds lowest of all
grades
int main()
{
GradeType grades; // the array holding the grades.
int numberOfGrades; // the number of grades read.
int pos; // index to the array.
float avgOfGrades; // contains the average of the grades.
int highestGrade; // contains the highest grade.
int lowestGrade; // contains the lowest grade.
// Read in the values into the array
pos = 0;
cout << "Please input a grade from 1 to 100, (or -99 to
stop)" << endl;
cin >> grades[pos];
while (grades[pos] != -99)
{
// Fill in the code to read the grades
}
numberOfGrades = ; // Fill blank with appropriate identifier
// call to the function to find average
avgOfGrades = findAverage(grades, numberOfGrades);
cout << endl << "The average of all the grades is "
<< avgOfGrades << endl;
// Fill in the call to the function that calculates highest
grade
cout << endl << "The highest grade is " <<
highestGrade << endl;
// Fill in the call to the function that calculates lowest
grade
// Fill in code to write the lowest to the screen
return 0;
}
//********************************************************************************
// findAverage
//
// task: This function receives an array of integers and its
size.
// It finds and returns the average of the numbers in the
array
// data in: array of floating point numbers
// data returned: average of the numbers in the array
//
//********************************************************************************
float findAverage (const GradeType array, int size)
{
float sum = 0; // holds the sum of all the numbers
for (int pos = 0; pos < size; pos++)
sum = sum + array[pos];
return (sum / size); //returns the average
}
//****************************************************************************
// findHighest
//
// task: This function receives an array of integers and its
size.
// It finds and returns the highest value of the numbers in the
array
// data in: array of floating point numbers
// data returned: highest value of the numbers in the array
//
//****************************************************************************
int findHighest (const GradeType array, int size)
{
/ Fill in the code for this function
}
//****************************************************************************
// findLowest
//
// task: This function receives an array of integers and its
size.
// It finds and returns the lowest value of the numbers in the
array
// data in: array of floating point numbers
// data returned: lowest value of the numbers in the array
//
//****************************************************************************
int findLowest (const GradeType array, int size)
{
// Fill in the code for this function
}
In: Computer Science
Queues are often used to represent lists of things that are being processed according to the order in which they arrived -- i.e. "first come, first served".
Assignment
Write a program that simulates the minute-by-minute operation of a checkout line, such as one you might find in a retail store. Use the following parameters:
1) Customers arrive at the checkout line and stand in line until the cashier is free.
2) When they reach the front of the line, they occupy the cashier for some period of time (referred to as ServiceTime) measured in minutes.
3) After the cashier is free, the next customer is served immediately.
4) Customers arrive at the checkout line at ArrivalRate per minute. Use the function included below (randomChance()) to return the number of customers arriving in a given minute, determined randomly.
5) The line can only hold so many people, MaxLineSize, until new arriving customers get frustrated and leave the store without purchasing anything.
6) ServiceTime is determined at the point the customer reaches the cashier, and should be taken from the random interval MinServiceTime and MaxServiceTime -- use the function randomInt() provided.
7) The overall time of the simulation is SimulationTime, measured in minutes.
The program should take 6 inputs (to be read from a text file named simulation.txt, as numbers only, one per line, in this order):
- SimulationTime - total number of minutes to run the simulation (whole number).
- ArrivalRate - per-minute arrival rate of customers (a floating point number greater than 0 and less than 1). This number is the "percent chance" that a customer will arrive in a given minute. For example, if it is 0.4, there is a 40% chance a customer will arrive in that minute.
- MinServiceTime - the minimum expected service time, in minutes (whole number).
- MaxServiceTime - the maximum expected service time, in minutes (whole number).
- MaxLineSize - the maximum size of the line. If a new customer arrives and the line has this many customers waiting, the new customer leaves the store unserviced.
- IrateCustomerThreshold - nobody enjoys standing in line, right? This represents the number of minutes after which a customer becomes angry waiting in line (a whole number, at least 1). These customers do not leave, they only need to be counted.
At the end of each simulation, the program should output:
- The total number of customers serviced
- The total number of customers who found the line too long and left the store.
- The average time per customer spent in line
- The average number of customers in line
- The number of irate customers (those that had to wait at least IrateCustomerThreshold minutes)
You are free to use any STL templates as needed (queue or vector, for example).
An example input file is posted in this week's Module here.
Example Run
The output should look similar to this. This example is for the first test case in the sample file. Your output may vary somewhat because of the randomness in the simulation. In the below case, with ArrivalRate set to 0.1, we would expect about 200 people to arrive. If we add the number of customers serviced (183) with the customers leaving (25) that gives us a number (208) which is close enough to 200 to be possible for one run.
Simulation Results ------------------ Overall simulation time: 2000 Arrival rate: 0.1 Minimum service time: 5 Maximum service time: 15 Maximum line size: 5 Customers serviced: 183 Customers leaving: 25 Average time spent in line: 33.86 Average line length: 3.15 Irate customers 10
What to Submit
Submit your .cpp file (source code for your solution) in Canvas.
Random Functions
Use these provided functions for generating your random chance (for a customer arrival) and interval for service times.
bool randomChance(double prob) { double rv = rand() / (double(RAND_MAX) + 1); return (rv < prob); } int randomInt(int min, int max) { return (rand() % (max - min) + min); }
Before calling these functions be sure to seed the random number generator (you can do this in main()):
srand(time(0));
In: Computer Science
Write an if-else statement with multiple branches. If givenYear is 2101 or greater, print "Distant future" (without quotes). Else, if givenYear is 2001 or greater (2001-2100), print "21st century". Else, if givenYear is 1901 or greater (1901-2000), print "20th century". Else (1900 or earlier), print "Long ago". Do NOT end with newline C++
In: Computer Science
JAVA
Take in a user input.
if user input is "Leap Year" your program should run exercise 1
if user input is "word count" your program should run exercise 2
Both exercises should run in separate methods
Exercise 1:
write a java method to check whether a year(integer) entered by the user is a leap year or not.
Exercise 2:
Write a java method to count all words in a string.
In: Computer Science
Design, implement, and fully test a Python3 function that converts a number to words (words_from_number(number: int)). It should expect to be passed a natural number (such as 12345) and return the corresponding words (i.e., “twelve thousand three hundred forty-five”). Since Python integers can grow arbitrarily large, your code should be flexible, handling at least 20 digits (realistically, it’s just as easy up to 30 digits). Spell everything correctly, and use correct punctuation (hyphens for forty-five and thirty-seven, no commas or plurals). You may only use built-in Python functions, not any modules or third-party libraries!
IMPORTANT NOTE: please use/def: words_from_number(number:int). I've had a lot of chegg answers change it to something else when I didn't ask for that, thank you.
In: Computer Science
Machine Learning
do using python on jupyter notebook
1. Linear Regression
Dataset used: Diabetes from sklearn
You are asked to solve a regression problem in the Diabetes
dataset. Please review the Diabetes dataset used before creating a
program to decide which attributes will be used in the regression
process.
please use the cross-validation step to produce the best evaluation
of the model.
All you have to do is
• Perform linear regression using the OLS (Ordinary Least Square)
method (sklearn.linear_model.LinearRegression)
• Also do linear regression using additional regularization.
(Lasso)
• Also do linear regression by doing gradient descent algorithm
training (func: sklearn.linear_model.SGDRegressor)
• In Sklearn there are several other regression methods that can be
tried for use in Diabetes problems.
In: Computer Science