python: Implement a function that reverses a list of elements by pushing them onto
a stack in one order, and writing them back to the list in reversed order.
In: Computer Science
Write a Java program that implements a queue in a hospital. I want your program to ask the user to enter the number of patients then enter the patient number starting from 110 till the end of the queue then print number of patients waiting in the queue.
Suppose you have a queue D containing the numbers (1,2,3,4,5,6,7,8), in this order. Suppose further that you have an initially empty Stack S. Give a code fragment that uses S, to store the elements in the order (8,7,6,5,4,3,2,1) in D.
In: Computer Science
Define a problem with user input, user output, Switch and some
mathematical computation. Write the pseudocode, code and display
output.
Include source code and output. If no output explain the reason why
and what you are going to do make sure it does not happen again aka
learning from your mistakes.
Problem:
Pseudocode:
Code:
Output:
In: Computer Science
Question 1:Write a program that randomly generates 100 dates and
store them into a vector. Use the Date class provided . The dates
generated must be within 1000 days after 1/1/2000.
Question 2:Sort the 100 dates generated in Question 1 in ascending
order.
This is Class data.h.(Please don't change the data.h file)
data.h
#ifndef DATE_H_
#define DATE_H_
#include
#include
using namespace std;
class Date {
friend ostream &operator<<( ostream &,
const Date & );
private:
int day;
int month;
int year;
static const int days[]; // array of days per month
void helpIncrement(); // utility function for incrementing date
public:
Date(int=1, int=1, int=0);
void setDate(int,int,int);
bool leapYear( int ) const; // is date in a leap
year?
bool endOfMonth( int ) const; // is date at the end of month?
Date &operator++(); // prefix increment operator
Date operator++( int ); // postfix increment operator
const Date &operator+=( int ); // add days, modify object
bool operator<(const Date&) const;
void showdate();
};
const int Date::days[] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Date::Date(int d, int m, int y) {
day = d;
month = m;
year = y;
// initialize static member at file scope; one classwide copy
}
// set month, day and year
void Date::setDate( int dd, int mm, int yy )
{
year = yy;
month = ( mm >= 1 && mm <= 12 )? mm : 1;
// test for a leap year
if ( month == 2 && leapYear( year ) )
day = ( dd >= 1 && dd <= 29 ) ? dd : 1;
else
day = ( dd >= 1 && dd <= days[ month ] ) ? dd :
1;
} // end function setDate
// if the year is a leap year, return true; otherwise, return
false
bool Date::leapYear( int testYear ) const
{
if ( testYear % 400 == 0 ||
( testYear % 100 != 0 && testYear % 4 == 0 ) )
return true; // a leap year
else
return false; // not a leap year
} // end function leapYear
// determine whether the day is the last day of the month
bool Date::endOfMonth( int testDay ) const
{
if ( month == 2 && leapYear( year ) )
return testDay == 29; // last day of Feb. in leap year
else
return testDay == days[ month ];
} // end function endOfMonth
// function to help increment the date
void Date::helpIncrement()
{
// day is not end of month
if ( !endOfMonth( day ) )
day++; // increment day
else
if ( month < 12 ) // day is end of month and month < 12
{
month++; // increment month
day = 1; // first day of new month
} // end if
else // last day of year
{
year++; // increment year
month = 1; // first month of new year
day = 1; // first day of new month
} // end else
} // end function helpIncrement
// overloaded prefix increment operator
Date &Date::operator++()
{
helpIncrement(); // increment date
return *this; // reference return to create an lvalue
} // end function operator++
// overloaded postfix increment operator; note that the
// dummy integer parameter does not have a parameter name
Date Date::operator++( int )
{
Date temp = *this; // hold current state of object
helpIncrement();
// return unincremented, saved, temporary object
return temp; // value return; not a reference return
} // end function operator++
// add specified number of days to date
const Date &Date::operator+=( int additionalDays )
{
for ( int i = 0; i < additionalDays; i++ )
helpIncrement();
return *this; // enables cascading
} // end function operator+=
// overloaded output operator
ostream &operator<<( ostream &output, const Date
&d )
{
// static string monthName[ 13 ] = { "", "January",
"February",
// "March", "April", "May", "June", "July", "August",
// "September", "October", "November", "December" };
//
// output << d.day << " " << monthName[ d.month ]
<< " "<< d.year;
output << setfill('0')
<< setw(2)
<< d.day << '/'
<< setw(2)
<< d.month << '/'
<< setw(4)
<< d.year;
return output; // enables cascading
} // end function operator<<
bool Date::operator<(const Date& right) const {
return (year < right.year || (year == right.year
&& month < right.month) ||
(year ==
right.year && month == right.month && day <
right.day));
}
void Date::showdate()
{
cout << "The date is ";
cout << setfill('0')
<< setw(2) << day
<< '/'
<< setw(2) << month
<< '/'
<< setw(2) << year %
100
<< endl;
return;
}
#endif /* DATE_H_ */
In: Computer Science
Write a Python program that will process the text file, Gettysburg.txt, by calculating the total words and output the number of occurrences of each word in the file.
The program needs to open the file and process each line. You need to add each word to the dictionary with a frequency of 1 or update the word’s count by 1. You need to print the output from high to low frequency.
The program needs 4 functions.
The first function is called add_word where you add each word to the dictionary. The parameters are the word and a dictionary. There is no return value.
The second function is called Process_line where you strip off various characters, split out the words, and so on. The parameters are a line and a dictionary. It calls the add_word function with each processed word. There is no return value.
The third function is called Pretty_print where this will be the printing function. The parameter is a dictionary. There is no return value.
The fourth function is the main where it will open the file and call Process_line on each line. When finished, it will call the Pretty_print function to print the dictionary.
Gettysburg.txt
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.
Abraham Lincoln
November 19, 1863
In: Computer Science
Can someone please check to see if these are right? If not please explain thank you!
Convert the following decimal numbers to their binary-octet equivalent.
114 = 1110010
254 =11111110
229 =11100101
66 = 01000010
7 =00000111
255 =11111111
192 =11000000
In: Computer Science
I need some asistance understanding of what to do for this problem in javascript:
* Problem 9 - find the largest number in the list of arguments
*
* Allow any number of arguments to be passed to the function. Allow both
* String and Number arguments to be passed, but throw an error if any other
* type is passed to the function (e.g., Boolean, Date, etc.). If the list
* is empty (nothing passed to the function), return null. Otherwise, return
* the largest value that was passed to the function as an argument:
*
* findLargest(1, 2, '3', '4', 5) should return 5
* findLargest('5') should also return 5
* findLargest(5, 3, 2, 1) should also return 5
******************************************************************************/
function findLargest() {
// Your code here...
}
here are the test cases:
const { findLargest } = require('./solutions');
describe('Problem 9 - findLargest', function() {
test('should find the largest number in a list', function() {
let largest = findLargest(1, 2, 3);
expect(largest).toBe(3);
});
test('should find the largest number in a list of 1', function() {
const largest = findLargest(1);
expect(largest).toBe(1);
});
test('should find the largest number in a long list', function() {
// https://github.com/gromgit/jstips-xe/blob/master/tips/33.md
const list = Array.apply(null, { length: 5000 }).map(Function.call, Number);
const largest = findLargest.apply(null, list);
expect(largest).toBe(4999);
});
test('should work with negative numbers', function() {
const largest = findLargest(1, 2, 3, -1, -2, -3);
expect(largest).toBe(3);
});
test('should work with strings that are numbers', function() {
const largest = findLargest('1', '2', '3');
expect(largest).toBe(3);
});
test('should work with decimals', function() {
const largest = findLargest(0.01, 0.001);
expect(largest).toBe(0.01);
});
test('should throw if a Boolean is included in the list', function() {
function shouldThrow() {
findLargest(1, true, 3);
}
expect(shouldThrow).toThrow();
});
test('should throw if an Object is included in the list', function() {
function shouldThrow() {
findLargest(1, console, 3);
}
expect(shouldThrow).toThrow();
});
test('should throw if a null is included in the list', function() {
function shouldThrow() {
findLargest(1, null, 3);
}
expect(shouldThrow).toThrow();
});
test('should throw if a undefined is included in the list', function() {
function shouldThrow() {
findLargest(1, undefined, 3);
}
expect(shouldThrow).toThrow();
});
test('should return null if the list is empty', function() {
const largest = findLargest();
expect(largest).toBe(null);
});
});
In: Computer Science
Question 2 Consider the one-dimensional data set shown below.
x | 0.5 | 3.0 | 4.5 | 4.6 | 4.9 | 5.2 | 5.3 | 5.5 | 7.0 | 9.5 |
y | - | - | + | + | + | - | - | + | - | - |
Classify the data point x = 5.0 according to its 1st, 3rd, 5th, and 9th nearest neighbors using K-nearest neighbor classifier.
Question 3 Use data set mushrooms.csv available for developing supervised model. The data set contains two classes namely,edible and poisonous. Perform following analysis on the data set.
Data Set:
1. Understand distribution of classes in the data set using suitable plots.
2. Develop supervised models: Decision tree and k-nearest neighbor
3. Identify best k in Cross-validation evaluating method for supervised models in step 3.
4. Discuss results achieved by each supervised model using confusion matrix, sensitivity, specificity,accuracy, F1-score and ROC curve.
5. Provide your opinion on why there exist variation in performance by models.
In: Computer Science
I have a countdown sequence i have to do for a code, when the result is entered it starts to countdown, i tried imputting some codes but i am clueless ( javascript):
/*******************************************************************************
* Problem 3: create count-down number sequence strings
*
* A count-down sequence is a String made up of a descending list of numbers.
* For example, the count-down sequence for the number 3 would be:
*
* "321"
*
* Write the countDownSequence function below, allowing any number between
* 1 and 10 to be accepted. Otherwise, throw an error (see
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
*
* If we called countDownSequence(5) we'd expect to get:
*
* "54321"
*
* If we called countDownSequence(55) we'd expect to have an error thrown
*
* Error: only start values between 1 and 10 are valid
*
* @param {Number} start - the number to start counting down from (must be 10 or smaller).
******************************************************************************/
function countDownSequence(start) {
var ret = '';
while (start >= 0) {
ret += start;
if (start > 0) {
ret += '';
}
start--;
}
return ret;
// Your code here...
}
It has to pass these tests:
const { countDownSequence } = require('./solutions');
describe('Problem 3 - countDownSequence() function', function() {
test('proper count down sequence from 10', function() {
let start = 10;
let result = countDownSequence(start);
expect(result).toBe('10987654321');
});
test('proper count down sequence from 1', function() {
let start = 1;
let result = countDownSequence(start);
expect(result).toBe('1');
});
test('starting at 0 should throw', function() {
function shouldThrow() {
// Using 0 is invalid, this should throw
countDownSequence(0);
}
expect(shouldThrow).toThrow();
});
test('starting at a negative number should throw', function() {
function shouldThrow() {
// Using -100 is invalid, this should throw
countDownSequence(-100);
}
expect(shouldThrow).toThrow();
});
test('starting at a number greater than 10 should throw', function() {
function shouldThrow() {
// Using 11 is invalid, this should throw
countDownSequence(11);
}
expect(shouldThrow).toThrow();
});
});
In: Computer Science
(C++)
In a file called pp7c.cpp, write a function called
printMoney that has one parameter, a double, and it prints
this parameter out formatted like a dollar amount with $ and
exactly 2 digits to the right of the decimal. Write a driver that
declares an array of monetary amounts like this:
double amounts[MAX_AMOUNTS];
and uses a while or do while loop to ask the user for monetary
amounts with -1 for the amount as a sentinel value to put values in
the array, amounts. Do not allow the user to enter more than
MAX_AMOUNTS numbers. This loop must count how many numbers are
placed in the amounts array as the array may be partially filled.
After using a do or do while loop to fill the array, write a for
loop to call the printMoney function to print all of the
values in the amounts array. The constant and function declarations
are shown below.
const int MAX_AMOUNTS = 10;
void printMoney( double m );
In: Computer Science
Perform SVM training and testing using SMS spam data set spam.csv . The objective is the predict the class of a new SMS using SVM classifier. The data set is a collection of a set of SMS tagged messages that have been collected for SMS Spam research. It contains one set of SMS messages in English of 5,574 messages, tagged according being ham (legitimate) or spam. The files contain one message per line. Each line is composed by two columns: v1 contains the label (ham or spam) and v2 contains the raw text.
Data set: The details of learning and testing task is as follows:
1. Understand distribution of classes in the data set using suitable plots.
2. Plot distribution of frequent words under “spam" and “ham" classes.
3. Preprocess the data set if required.
4. Apply SVM classifier.
5. Use Cross validation and Hold-out approaches to learn and evaluate SVM classifier.
6. Discuss results achieved by SVM classifier using confusion matrix, sensitivity, specificity and accuracy.
Question 3 Consider a problem where we are given collection of reviews of a movie by 5 people. Each review is a sentence summarising the comments given by the person. The review is classified as either good or bad.
1. Create example supervised data set on this problem.
2. Formulate Naive Bayes classifier on this data set to predict a new review in defined category
[Hint:- Please refer to the given example Analyzing Textual Data with Natural Language Processing.pdf for solving question 2 & 3.]
In: Computer Science
Can you write code in Java to find the power set of a given set? For example if S={a,b} the power set is P={{},{a},{b},{a,b}} ( you can also choose any of your favorite programming language). Explaning the code in comment please.
In: Computer Science
Write a python program that has:
CivilIdNumber
Name
Telephone#
Address
CivilIdNumber
Name
Telephone#
Address
CivilIdNumber
Name
Telephone#
Address
Etc
A record always consists of 4 lines (civilid, name, telephone and address). You can find a sample input file on last page of this assignment, copy it and past it into a .txt file and save it to the same directory that your python program resides on.
The function then creates a dictionary with the civilIdNuber as the key and the rest of the record as a list with index 0 being the name, index 1 being the telephone# and index 2 being Address.
When finishing reading all records the function then returns the dictionary
CivilId: civilidnumber
Name: name
Address: address
Telephone Number: telephone
CivilId: civilidnumber
Name: name
Address: address
Telephone Number: telephone
Etc…
In: Computer Science
Code an application program that keeps tracks of
srudent information at your college:names, identification numbers,
and grade point averages in a fully encapsulated (homogenous)
sorted array-based data structure. When launched, the user will be
asked to input the maximum size of data set, the initial number of
students, and the initial data set. once this is complete, the user
will be presented with the following menu:
Enter:1 to insert a new student's info
2 to fetch and out put a student's info
3 to delete student info
4 to update student info
5 to output all the student info in sorted order
6 to exit program
note: please use Java language to create this program and please
write comments for each statement that what is happening. i know
there are same questions solution posted in chegg, but i want some
unique from others
In: Computer Science
Problem 9 - PYTHON
There is a CSV-formatted file called olympics2.csv. Write code that creates a dictionary named country_olympians where the keys are country names and the values are lists of unique olympians from that country (no olympian's name should appear more than once for a given country).
Name,Sex,Age,Team,Event,Medal
A Dijiang,M,24,China,Basketball,NA
A Lamusi,M,23,China,Judo,NA
Gunnar Nielsen Aaby,M,24,Denmark,Football,NA
Edgar Lindenau Aabye,M,34,Sweden,Tug-Of-War,Gold
Christine Jacoba Aaftink,F,21,Netherlands,Speed Skating,NA
Christine Jacoba Aaftink,F,21,Netherlands,Speed Skating,NA
Christine Jacoba Aaftink,F,25,Netherlands,Speed Skating,NA
Christine Jacoba Aaftink,F,25,Netherlands,Speed Skating,NA
Christine Jacoba Aaftink,F,27,Netherlands,Speed Skating,NA
Christine Jacoba Aaftink,F,27,Netherlands,Speed Skating,NA
Per Knut Aaland,M,31,United States,Cross Country Skiing,NA
Per Knut Aaland,M,31,United States,Cross Country Skiing,NA
Per Knut Aaland,M,31,United States,Cross Country Skiing,NA
Per Knut Aaland,M,31,United States,Cross Country Skiing,NA
Per Knut Aaland,M,33,United States,Cross Country Skiing,NA
Per Knut Aaland,M,33,United States,Cross Country Skiing,NA
Per Knut Aaland,M,33,United States,Cross Country Skiing,NA
Per Knut Aaland,M,33,United States,Cross Country Skiing,NA
John Aalberg,M,31,United States,Cross Country Skiing,NA
John Aalberg,M,31,United States,Cross Country Skiing,NA
John Aalberg,M,31,United States,Cross Country Skiing,NA
John Aalberg,M,31,United States,Cross Country Skiing,NA
John Aalberg,M,33,United States,Cross Country Skiing,NA
John Aalberg,M,33,United States,Cross Country Skiing,NA
John Aalberg,M,33,United States,Cross Country Skiing,NA
John Aalberg,M,33,United States,Cross Country Skiing,NA
"Cornelia ""Cor"" Aalten
(-Strannood)",F,18,Netherlands,Athletics,NA
"Cornelia ""Cor"" Aalten
(-Strannood)",F,18,Netherlands,Athletics,NA
Antti Sami Aalto,M,26,Finland,Ice Hockey,NA
"Einar Ferdinand ""Einari"" Aalto",M,26,Finland,Swimming,NA
Jorma Ilmari Aalto,M,22,Finland,Cross Country Skiing,NA
Jyri Tapani Aalto,M,31,Finland,Badminton,NA
Minna Maarit Aalto,F,30,Finland,Sailing,NA
Minna Maarit Aalto,F,34,Finland,Sailing,NA
Pirjo Hannele Aalto (Mattila-),F,32,Finland,Biathlon,NA
Arvo Ossian Aaltonen,M,22,Finland,Swimming,NA
Arvo Ossian Aaltonen,M,22,Finland,Swimming,NA
Arvo Ossian Aaltonen,M,30,Finland,Swimming,Bronze
Arvo Ossian Aaltonen,M,30,Finland,Swimming,Bronze
Arvo Ossian Aaltonen,M,34,Finland,Swimming,NA
Juhamatti Tapio Aaltonen,M,28,Finland,Ice Hockey,Bronze
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,Bronze
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,Gold
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,Gold
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,28,Finland,Gymnastics,Gold
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,Bronze
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Paavo Johannes Aaltonen,M,32,Finland,Gymnastics,NA
Timo Antero Aaltonen,M,31,Finland,Athletics,NA
Win Valdemar Aaltonen,M,54,Finland,Art Competitions,NA
In: Computer Science