Write a program that has a function (named getNumStats()) that will return a string that has stats on the number entered.
The prototype is:
string getNumStats(double);
The stats are:
Is the number an integer or a double?
The polarity (is it positive or negative; 0 counts as positive)
The parity (is it odd or even)
Is it a prime number? (for this program, 1 is considered a prime number)
For example, if the following lines of code are executed
double dNum = 14.06;
string test = getNumStats(dNum)
cout << test << endl;
The output that appears on the screen will be:
14.06 is a double
It is positive
It does not have parity
It is not a prime number
Another run is:
double dNum = -27.371;
string test = getNumStats(dNum)
cout << test << endl;
The output that appears on the screen will be:
-23.371 is a double
It is negative
It does not have parity
It is not a prime number
Note: your first line of output may or may not show trailing zeros. You may add that feature to always show zeros (even if the number is an integer)
In: Computer Science
How can I analyze "Enron Dataset" using ONLY "Naive Bayes model" or "SVM(Support Vector Machine) model" or "Decision Trees model" or "Random Forest model" or "K Nearest Neighbors model". And for what purpose the result can be used? Please give me some rough ideas and methods. No need to right down the Python codes.
In: Computer Science
Explain the similarities and differences between Drop (a table), Truncate (the data), and Delete (the data).
In: Computer Science
I created a shoppingcart program but I'm getting a few compilation failed errors:
1) Tests that ItemToPurchase("Bottled Water", "Deer Park, 12 oz.", 1, 10) correctly initializes item compilation failed
2) Tests default constructor and accessors for ShoppingCart Compilation failed
3)Tests ShoppingCart("John Doe", "February 1, 2016") correctly initializes cart Compilation failed
4) Tests that getNumItemsInCart() returns 6 (ShoppingCart) compilation failed
5) Test that getCostOfCart() returns 9 (ShoppingCart) compilation failed
Complete program:
itemtopurchase.java
public class ItemToPurchase {
// instance variables
private String itemName;
private String itemDescription;
private int itemPrice;
private int itemQuantity;
// default constructor
public ItemToPurchase() {
this.itemName = "none";
this.itemDescription = "none";
this.itemPrice = 0;
this.itemQuantity = 0;
}
public ItemToPurchase(String itemName, int itemPrice, int
itemQuantity,String itemDescription) {
this.itemName = itemName;
this.itemDescription = itemDescription;
this.itemPrice = itemPrice;
this.itemQuantity = itemQuantity;
}
// method to set name of the item
public void setName(String name) {
itemName = name;
}
// method to set price of the item
public void setPrice(int price) {
itemPrice = price;
}
// method to set quantity of the item
public void setQuantity(int quantity) {
itemQuantity = quantity;
}
public void setDescription(String description) {
itemDescription = description;
}
// method to get name of the item
public String getName() {
return itemName;
}
// method to get price of the item
public int getPrice() {
return itemPrice;
}
// method to get quantity of the item
public int getQuantity() {
return itemQuantity;
}
public String getDescription() {
return itemDescription;
}
public void printItemPurchase() {
System.out.println(itemName + " " + itemQuantity + " @ $" +
itemPrice + " = $" + (itemPrice * itemQuantity));
}
public void printItemDescription() {
System.out.println(itemName+": "+itemDescription);
}
}
shoppingcart.java
import java.util.ArrayList;
public class ShoppingCart {
//instance variables
private String customerName;
private String currentDate;
private ArrayList<ItemToPurchase> cartItems = new
ArrayList<ItemToPurchase>();
//Default constructor
public ShoppingCart() {
customerName = "";
currentDate = "";
}
//parameterized constructor
public ShoppingCart(String customerName, String currentDate)
{
this.customerName = customerName;
this.currentDate = currentDate;
}
//getter methods
public String getCustomerName() {
return customerName;
}
public String getCurrentDate() {
return currentDate;
}
//add items
public void addItem(ItemToPurchase item) {
cartItems.add(item);
}
//remove item
public void removeItem(String name) {
for (ItemToPurchase i : cartItems) {
if (i.getName().equalsIgnoreCase(name)) {
cartItems.remove(i);
return;
}
}
System.out.println("Item not found in cart");
}
//modify the item
public void modifyItem(ItemToPurchase item) {
for (int i = 0; i < cartItems.size(); i++) {
if (cartItems.get(i).getName().equalsIgnoreCase(item.getName()))
{
if (!item.getDescription().equals("none") &&
!(item.getPrice() == 0) && !(item.getQuantity() == 0))
{
cartItems.add(i, item);
return;
}
}
}
System.out.println("Item not found in cart. Nothing modified");
}
//get total number of items in the cart
public int getNumItemsIncart() {
int sum = 0;
for (ItemToPurchase i : cartItems) {
sum += i.getQuantity();
}
return sum;
}
//get total cost of items in the cart
public int getCostOfcart() {
int sum = 0;
for (ItemToPurchase i : cartItems) {
sum += i.getPrice();
}
return sum;
}
//printing total of each items
public void printTotal() {
System.out.println(customerName + "'s Shopping Cart - " +
currentDate);
if (cartItems.isEmpty()) {
System.out.println("Shopping Cart is Empty");
return;
}
System.out.println("Number of Items: " +
cartItems.size());
System.out.println();
for (ItemToPurchase i : cartItems) {
i.printItemPurchase();
}
System.out.println();
System.out.println("Total: $" + getCostOfcart());
}
//printing description of all items
public void printDescription() {
System.out.println(customerName + "'s Shopping Cart - " +
currentDate);
System.out.println();
if (cartItems.isEmpty()) {
System.out.println("Shopping Cart is Empty");
return;
}
System.out.println("Item Descriptions: ");
for (ItemToPurchase i : cartItems) {
i.printItemDescription();
}
}
}
shoppingcartmanager.java
import java.util.Scanner;
public class ShoppingCartManager {
// method to add an item in the cart
public static void addCartItem(Scanner scan, ShoppingCart cart)
{
String itemName, itemDescription;
int itemPrice, itemQuantity;
System.out.println("ADD ITEM TO CART");
System.out.print("Enter the item name : ");
itemName = scan.nextLine();
System.out.print("Enter the item description : ");
itemDescription = scan.nextLine();
System.out.print("Enter the item price : ");
itemPrice = scan.nextInt();
System.out.print("Enter the item quantity : ");
itemQuantity = scan.nextInt();
scan.nextLine();
cart.addItem(new ItemToPurchase(itemName, itemPrice, itemQuantity, itemDescription));
}
// method to remove an item from the cart
public static void removeCartItem(Scanner scan, ShoppingCart cart)
{
String itemName;
System.out.println("REMOVE ITEM FROM CART");
System.out.print("Enter the name of item to remove : ");
itemName = scan.nextLine();
cart.removeItem(itemName);
}
// method to change quantity of the cart
public static void changeItemQuantity(Scanner scan, ShoppingCart
cart) {
String itemName;
int itemQuantity;
System.out.println("CHANGE ITEM QUANTITY");
System.out.print("Enter the item name : ");
itemName = scan.nextLine();
System.out.print("Enter the new quantity : ");
itemQuantity = scan.nextInt();
scan.nextLine();
cart.modifyItem(new ItemToPurchase(itemName, 0, itemQuantity,
"none"));
}
// method to display menu choices and perform the operations on
the cart until
// the user quits
public static void printMenu(ShoppingCart cart) {
String choice;
Scanner scan = new Scanner(System.in);
do {
System.out.println("\nMENU");
System.out.println("a - Add item to cart");
System.out.println("d - Remove item from cart");
System.out.println("c - Change item quantity");
System.out.println("i - Output items' description");
System.out.println("o - Output shopping cart");
System.out.println("q - Quit");
System.out.print("\nChoose an option : ");
choice = scan.nextLine();
if (choice.equalsIgnoreCase("a")) {
addCartItem(scan, cart);
} else if (choice.equalsIgnoreCase("d")) {
removeCartItem(scan, cart);
} else if (choice.equalsIgnoreCase("c")) {
changeItemQuantity(scan, cart);
} else if (choice.equalsIgnoreCase("o")) {
System.out.println("OUTPUT SHOPPING CART");
cart.printTotal();
} else if (choice.equalsIgnoreCase("i")) {
System.out.println("OUTPUT ITEMS' DESCRIPTION");
cart.printDescription();
} else if (!choice.equalsIgnoreCase("q"))
System.out.println("Invalid choice");
} while (!choice.equalsIgnoreCase("q"));
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
// taking user input
System.out.println("Enter Customer's Name:");
String name = sc.nextLine();
System.out.println("Enter Today's Date:");
String date = sc.nextLine();
// printing user input
System.out.println();
System.out.println("Customer Name: " + name);
System.out.println("Today's Date: " + date);
ShoppingCart cart = new ShoppingCart(name, date);// created
shopping cart object
printMenu(cart);
}
}
In: Computer Science
How could I implement the contain and min method for a tree in this code.
import java.util.List;
import edu.princeton.cs.algs4.*;
class ProgrammingAssignment1 {
//////////////////// EXERCICE 1: TWO THREE TREES
static public <Key extends Comparable<Key>>
int size (NakedTree<Key> tree) {
if (tree == null)
return 0;
int val = tree.getNKeys ();
for (int i = 0; i <= tree.getNKeys (); ++i)
val += size (tree.getChild (i));
return val;
}
//////// EXERCICE 1.1: contains AND min
static public <Key extends Comparable<Key>>
boolean contains (NakedTree<Key> tree, Key key) {
}In: Computer Science
Hello, I have a problem with understanding this line.
forEach(value.split("<br>"), line, line.trim()).slice(-3).join("\n")
This line is for the open refine program. Could you tell me what this line is trying to do? I have no idea what this is for...
For your information, this line appeared when professor was talking about 'Fetching and Parsing HTML'..
Thank you for answering my question and have a good day!
p.s. My professor told us to insert that line in the expression box and try to figure out what this expression means... As I'm not majoring in CS, it's too difficult for me to understand..;(
In: Computer Science
Discuss the open-source tools in general. What are the advantages versus disadvantages? What is the life-long learning lesson you think you are able to acquire with this type of assignment? Discuss ethical and global issues.
In: Computer Science
In: Computer Science
#include <stdio.h>
int main(void) {
int input = -1;
double average = 0.0;
/* Use this for your input */
scanf("%d", &input);
/* This is the only output you need */
printf("%.1lf", average);
return 0;
}
Please write a C coding program (make it simple coding) that find the average of sequence integer. when user enter integers, once at a time. Also, If the user enters 0 (zero), the code will calculates the average and then prints it, and then exits.
In: Computer Science
In: Computer Science
I need to create a servlet that takes in an input that will do the following calculations.
In: Computer Science
When you buy a new computer what would you do to harden it
In: Computer Science
Provide two classification scenarios where you can use classification tree models but not logistic regression models. For each problem, identify a target variable and four possible predictor variables.
In: Computer Science
Part II: Programming Questions
NOTE: CODING LANGUAGE IS C#
PQ1. How would you declare the following scalar and non-scalar (vector) variables?
PQ2.
PQ3.
PQ4. The algorithm for checking if a number is a prime is to check if it is divisible by any number less than itself other than 1. (Divisibility implies that if you use the modulus operator, %, the result will be 0). Write a function to check if a number is a prime.
In: Computer Science
Write a C program to implement Jacobi iterative method for sovling a system of linear equations. Use the skeleton code.
skeleton code:
/*
CS288 HOMEWORK 8
Your program will take in two command-line parameters: n and error
command: jacobi 5 0.0001
command: jacobi 10 0.000001
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <math.h>
#define N 100
#define MAX_ITER 10000
int jacobi();
void init();
int convergence();
void srand();
void print_vector();
void print_equation();
float a[N][N], b[N];
float x[N], buf[N];
int n;
float error;
int main(int argc, char **argv){
int n_iter; /* number of iterations */
n = atoi(argv[1]);
error = atof(argv[2]);
init(); /* initalize a, x0 and b - DO not change */
n_iter = jacobi();
return 0;
}
int jacobi(){
int i,j,k;
float sum;
// ...
// ...
// ...
return k;
}
// returns 1 if converged else 0
int convergence(int iter){
int i,j,k,flag=1;
// ...
// ...
// ...
return flag;
}
// Try not to change this. Use it as is.
void init(char **argv){
int i,j,k,flag=0;
float sum;
int seed = time(0) % 100; /* seconds since 1/1/1970 */
srand(seed);
for (i=0;i<n;i++) {
for (j=0;j<n;j++) {
a[i][j] = rand() & 0x7;
if (rand() & 0x1) a[i][j] = -a[i][j];
}
sum = 0;
for (j=0;j<n;j++) if(i!=j) sum = sum + abs(a[i][j]);
if (a[i][i] < sum) a[i][i] = sum + a[i][i];
}
for (i=0;i<n;i++) x[i]=1;
srand(seed);
for (i=0;i<n;i++){
b[i]=rand() & 0x7;
if (rand() & 0x1) b[i] = -b[i];
}
print_equation();
}
void print_equation(){
int i,j;
printf("A*x=b\n");
for (i=0;i<n;i++) {
for (j=0;j<n;j++) printf("%2d ",(int)(a[i][j]));
printf(" * x%d = %d\n",i,(int)(b[i]));
}
printf("\n");
}
void print_vector(float *l){
int i;
for (i=0; i<n; i++) printf("%.6f ",l[i]);
printf("\n");
}
// end of fileIn: Computer Science