Write a program in Java that reads in a set of positive integers and outputs how many times a particular number appears in the list. You may assume that the data set has at most 100 numbers and -999 marks the end of the input data. The numbers must be output in increasing order. For example, for the data 15 40 28 62 95 15 28 13 62 65 48 95 65 62 65 95 95 -999
The output is
Number Count
13 1
15 2
28 2
40 1
48 1
62 3
65 3
95 4
In: Computer Science
Python Programming
An emirp (prime spelled backward) is a nonpalindromic prime number whose reversal is also a prime. For example, 17 and 71 are prime numbers, so 17 and 71 are emirps. Write a program that displays the first 10 emirps.
In: Computer Science
C++ program that reads a positive integer number from a user and displays all binary numbers from 0 to the number.
For the program, you can assume that the input number is a number between 0 and 100.
Sample Run 1: Assume that the user typed the following number.
5
This is the correct output of your program.
000
001
010
011
100
101
Sample Run 2: Assume that the user typed the following number.
0
This is the correct output of your program.
0
Sample Run 3: Assume that the user typed the following number.
3
This is the correct output of your program.
00
01
10
11
In: Computer Science
Creating Enumerations In this section, you create two enumerations that hold colors and car model types. You will use them as field types in a Car class and write a demonstration program that shows how the enumerations are used.
1. Open a new file in your text editor, and type the following Color enumeration: enum Color {BLACK, BLUE, GREEN, RED, WHITE, YELLOW};
2. Save the file as Color.java.
3. Open a new file in your text editor, and create the following Model enumeration: enum Model {SEDAN, CONVERTIBLE, MINIVAN};
4. Save the file as Model.java. Next, open a new file in your text editor, and start to define a Car class that holds three fields: a year, a model, and a color.
public class Car {
private int year;
private Model model;
private Color color;
5. Add a constructor for the Car class that accepts parameters that hold the values for year, model, and color as follows:
public Car(int yr, Model m, Color c) {
year = yr;
model = m;
color = c;
}
6. Add a display() method that displays a Car object’s data, then add a closing curly brace for the class.
public void display() {
System.out.println("Car is a " + year + " " + color + " " + model);
}
}
7. Save the file as Car.java.
8. Open a new file in your text editor, and write a short demonstration program that instantiates two Car objects and assigns values to them using enumeration values for the models and colors.
public class CarDemo {
public static void main(String[] args) {
Car firstCar = new Car(2014, Model.MINIVAN, Color.BLUE);
Car secondcar = new Car(2017, Model.CONVERTIBLE, Color.RED);
firstCar.display();
secondcar.display();
}
}
9. Save the file as CarDemo.java, and then compile and execute it.
the output should be something like
"Car is a 2014 BLUE MINIVAN
Car is a 2017 RED CONVERTIBLE"
in Java
In: Computer Science
Here is the problem I am working on. I need to write a py program that:
Calculates a Cartesian Product Output, A x B of 2 lists. I want to limit each list to 5 numbers. It is kind of working, but I can't help think that there is a simpler way to express this problem. Please advise...
Here is my code:
def CartesianProductOutput(A,B):
lst = []
for x in A:
t = []
t.append(x)
for y in B:
temp = []
for x in t:
temp.append(x)
temp.append(y)
lst.append(temp)
return lst
A = [1,2,3,4,5]
B = [1,2,3,4,5]
print(CartesianProductOutput(A,B))
In: Computer Science
Hello, I very stuck on this c++ blackjack project and was wondering if anyone can offer help and guidance on this subject
can someone help he with part 4 i have no idea how to approach the problem and how to do it
I have compeleted a few parts to this project they are listed below
Part 1 – Displaying Cards Write a function to display (print) a card. sample program output void displayCard(int card) Prints the name of the card (ten of spades, queen of diamonds etc.). The parameter should be a value between 1 and 13, from which the type of card can be determined (1 = ace, 2 = two, …, 10, == ten, 11 = jack, 12 = queen, 13 = king). The card suit (clubs, diamonds, hearts or spades) should be determined randomly.
Part 2 – Generating Cards Write a function to get a card. int getCard() Returns a random value between 1 and 13, representing a card (ace, 2, …, queen, king). You do not have to keep track of which cards are dealt. So, if the game deals the queen of spades five times in row that is perfectly acceptable.
Part 3 – Determining a Cards Score Write a function to return a card's score. int cardScore(int card) Returns a value between 2 and 11 as described in the rules. Recall that the score is the card's value except that aces are worth 11 and face cards are worth 10. The card parameter represents the card for which the score is to be determined.
Part 4 – Dealing Cards Now that you've completed Parts 1 and 2 you can write a function that handles dealing cards. int deal(bool isPlayer, bool isShown) This function is responsible for: 1. Generating the next card to be dealt (Part 1) 2. Printing out what card was dealt (Part 2) and to whom, if needed (see below) 3. Returning the card's score (Part 3) The two Boolean parameters are related to printing out the card. The isPlayer parameter is used to determine whether the word PLAYER or DEALER should be printed at the start of the output. The isShown parameter is used to determine if the card should be printed – recall that the second card dealt to the dealer is hidden.
MYCODE
#include
#include
#include
#include
using namespace std;
void displaycard(int card, int suits){
string cardtype[13] = { "Ace of", "Two of", "Three of" , "Four of" , "Five of" , "Six of", "Seven of","Eight of", "Nine of", "Ten of", "Jack of","Queen of","King of" };
cout << cardtype[card];
string suit[4]={" hearts"," diamonds"," spades"," clubs"};
cout << suit[suits];
}
int getcard(){
int card;
card = rand()%13;
return card;
}
int getsuit(){
int suits;
suits = rand() % 4;
return suits;
}
int cardScore(int card)
{
if (card == 11 || card == 12 || card == 13)
{
card = 10;
}
else if (card == 1)
{
card = 11;
}
else
{
card = card;
}
return card;
}
int deal(bool isPlayer, bool isShown){
int cardWhom;
int dealer;
if (cardWhom == true||dealer == true ){
cout << "PLAYER"<< endl;
}
else {
cout << "DEALER" << endl;
}
}
int main(){
srand((unsigned)time(0));
return 0;
}
In: Computer Science
IMPLEMENT the Following instructions into the String.hpp and String.cpp provided. DO NOT just simply copy the code I give you as your answer
Intructions:
Implementation:
For your String class:
Implement method String String::substr(int start_pos, int count) const;. This will return the specified substring starting at start_pos and consisting of count characters (there will be less than count if it extends past the end of the string).
Implement method int String::find(char ch, int start_pos) const; which gives the first location starting at start_pos of the character ch or -1 if not found.
Implement method int String::find(const String & s, int start_pos) const; which gives the first location starting at start_pos of the substring s or -1 if not found.
Implement a method std::vector<String> String::split(char) const;
You will use std::vector<> (need to include <vector>) for storing the results of parsing the input data.
This method will return a vector of String split up based on a supplied character. For example given s = "abc ef gh", the call s.split(' ') will return a vector with three strings: "abc", "ef", and "gh".
std::vector has a number of operations defined including operator[], and size (number of elements in the vector).
-------------------------------------------------------------------------------------
string.hpp
-------------------------------------------------------------------------------------
#ifndef STRING_HPP #define STRING_HPP #include <iostream> /** * @invariant str[length()] == 0 * && length() == capacity() * && capacity() == stringSize - 1 */ class String { private: // helper constructors and methods String(int); String(int, const char *); void reset_capacity (int); char * str; // size includes NULL terminator int string_size; public: // constructor: empty string, String('x'), and String("abcd") String(); String(char); String(const char *); // copy ctor, destructor, constant time swap, and assignment String(const String &); ~String(); void swap (String &); String & operator= (String); // subscript: accessor/modifier and accessor char & operator[](int); char operator[](int) const; // max chars that can be stored (not including null terminator) int capacity() const; // number of char in string int length () const; // concatenation String operator+ (const String &) const; String & operator+=(String); // relational methods bool operator==(const String &) const; bool operator< (const String &) const; // i/o friend std::ostream& operator<<(std::ostream &, const String &); friend std::istream& operator>>(std::istream &, String &); }; // free functios for concatenation and relational String operator+ (const char *, const String &); String operator+ (char, const String &); bool operator== (const char *, const String &); bool operator== (char, const String &); bool operator< (const char *, const String &); bool operator< (char, const String &); bool operator<= (const String &, const String &); bool operator!= (const String &, const String &); bool operator>= (const String &, const String &); bool operator> (const String &, const String &); #endif
-------------------------------------------------------------------------------
string.cpp
-------------------------------------------------------------------------------
#include <cstring> #include <iostream> #include <cassert> #include "string.hpp" String::String(int n){ string_size = n; str = new char[n]; str[0] = '\0'; } String::~String(){ delete [] str; } String::String(int x, const char *str1){ string_size = x; str = new char[x]; int pos = 0; while(str1[pos] != '\0') { str[pos] = str1[pos]; ++pos; } str[pos] = '\0'; } void String::reset_capacity(int x){ String str1(x, str); swap(str1); } String::String(){ str = new char[1]; str[0] = '\0'; string_size = 1; } String::String(char ch){ string_size = 2; str = new char[string_size]; str[0] = ch; str[1] = '\0'; } String::String(const char* s){ int counter = 0; while(s[counter] != '\0'){ ++counter; } string_size = counter + 1; str = new char[string_size]; for(int i = 0; i < counter ; i++){ str[i] = s[i]; } str[counter] = '\0'; } String::String(const String& s){ string_size = s.string_size; str = new char[string_size]; int pos = 0; for(int i = 0; i < string_size; ++i){ str[i] = s.str[i]; ++pos; } } int String::length() const{ int size = 0; while(str[size] != '\0') ++size; return size; } int String::capacity() const{ return string_size - 1; } String& String::operator=(String str1){ string_size = str1.string_size; for(int i = 0; i < string_size; i++){ str[i] = str1.str[i]; } return *this; } char& String::operator[](int i){ assert(i >= 0); assert(i <= length()); return str[i]; } void String::swap(String& str1){ int tempStr = string_size; string_size = str1.string_size; str1.string_size = tempStr; char* tempStr1 = str; str = str1.str; str1.str = tempStr1; } char String::operator[](int i) const{ assert(i >= 0); assert(i <= length()); return str[i]; } bool String::operator==(const String& rhs) const{ int pos = 0; while(str[pos] != '\0' && str[pos] == rhs.str[pos]){ ++pos; } return str[pos] == rhs.str[pos]; } std::istream& operator>>(std::istream& in, String& rhs){ in >> rhs.str; return in; } std::ostream& operator<<(std::ostream& out, const String& rhs){ out << rhs.str; return out; } bool String::operator<(const String& rhs) const{ int pos = 0; while(str[pos] != '\0' && rhs.str[pos] != '\0' && str[pos] == rhs.str[pos]){ ++pos; } return str[pos] < rhs.str[pos]; } String String::operator+(const String& rhs) const{ int offset2 = (length() + rhs.length()) + 1; String result(offset2); int offset = length(); int count = 0; int pos = 0; while(str[count] != '\0'){ result.str[count] = str[count]; ++count; } while(rhs.str[pos] != '\0'){ result.str[offset + pos] = rhs.str[pos]; ++pos; } result.str[offset2 - 1] = '\0'; return result; } String& String::operator+=(String rhs){ int offset = length(); int pos = 0; int newSize = (length() + rhs.length()) + 1; String result(newSize); reset_capacity(newSize); for(int x = offset; x < newSize; ++x){ str[x] = rhs.str[pos]; ++pos; } str[newSize - 1] = '\0'; return *this; } String operator+(const char charArray[], const String& rhs){ String s(charArray); return rhs + s; } String operator+(char s, const String& rhs){ return s + rhs; } bool operator==(const char charArray[], const String& rhs){ if(charArray == rhs){ return true; } else{ return false; } } bool operator==(char s, const String& rhs){ if(s == rhs){ return true; } else{ return false; } } bool operator<(const char charArray[], const String& rhs){ if(charArray < rhs){ return true; } else{ return false; } } bool operator<(char s, const String& rhs){ if(s < rhs){ return true; } else{ return false; } } bool operator<=(const String& lhs, const String& rhs){ if(lhs < rhs || lhs == rhs){ return true; } else{ return false; } } bool operator!=(const String& lhs, const String& rhs){ if(lhs.length() != rhs.length()){ return true; } int pos = 0; while(lhs[pos] != rhs[pos]){ pos++; } if(pos == lhs.length()){ return true; } return false; } bool operator>=(const String& lhs, const String& rhs){ if(lhs > rhs || lhs == rhs) { return true; } else{ return false; } } bool operator>(const String& lhs, const String& rhs){ if(!(lhs <= rhs)){ return true; } else{ return false; } }
In: Computer Science
Searching an Array for an Exact Match C++
This question is on MindTap Cengage
Summary
In this lab, you use what you have learned about searching an array to find an exact match to complete a partially prewritten C++ program. The program uses an array that contains valid names for 10 cities in Michigan. You ask the user to enter a city name; your program then searches the array for that city name. If it is not found, the program should print a message that informs the user the city name is not found in the list of valid cities in Michigan.
The file provided for this lab includes the input statements and the necessary variable declarations. You need to use a loop to examine all the items in the array and test for a match. You also need to set a flag if there is a match and then test the flag variable to determine if you should print the the Not a city in Michigan.message. Comments in the code tell you where to write your statements. You can use the previous Mail Order program as a guide.
Instructions
Ensure the provided code file named MichiganCities.cppis open.
Study the prewritten code to make sure you understand it.
Write a loop statement that examines the names of cities stored in the array.
Write code that tests for a match.
Write code that, when appropriate, prints the message Not a city in Michigan.
Execute the program by clicking the Run button
at the bottom of the screen. Use the following as
input:
Chicago
Brooklyn
Watervliet
Acme
// MichiganCities.cpp - This program prints a message for invalid cities in Michigan.
// Input: Interactive
// Output: Error message or nothing
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Declare variables
string inCity; // name of city to look up in array
const int NUM_CITIES = 10;
// Initialized array of cities
string citiesInMichigan[] = {"Acme", "Albion", "Detroit", "Watervliet", "Coloma", "Saginaw", "Richland", "Glenn", "Midland", "Brooklyn"};
bool foundIt = false; // Flag variable
int x; // Loop control variable
// Get user input
cout << "Enter name of city: ";
cin >> inCity;
// Write your loop here
// Write your test statement here to see if there is
// a match. Set the flag to true if city is found.
// Test to see if city was not found to determine if
// "Not a city in Michigan" message should be printed.
return 0;
} // End of main()
In: Computer Science
1. write SQL statements to create the following two
tables:
a) Department table that contains the following
columns(dept_no,deptname,location) set the deptno to be the primary
key.
b) Employee table contains the following
columns(emp_no,empname,deptno,salary)set the emp_no to be the
primary key and dept_no to be the foreign key.
2. Write SQL statements to Insert the following 3 rows in Employee
table:
(101,’Sami’,’D-101’,5000)
(102,’Yousef’,’D-101’,4000)
(103,’Sami’,’D-102’,7000)
3. Write SQL statements to Insert the following 3 rows in
Department table:
(‘D-101’,’Marketing’,’loc1’)
(‘D-102’,’Sales’,’loc2’)
(‘D-103’,’Finance’,’loc3’)
4. Create a view for employee at marketing department.
In: Computer Science
Designing A New Arena :
You work for a company that has been tasked with designing a
proposed seating plan for an NHL team’s new arena. Currently the
NHL team plays in a rink similar to the one shown here:
Parameters of the Plan
PART A – SEATS AND ROWS
Using the parameters above, and your understanding of sequences and series:
Be sure to explain in detail any assumptions you
make.
PART B – TICKET PRICES
The team’s current arena charges:
The team has suggested modifying their current plan to use a geometric sequence, and decrease the price for a seat in each subsequent row by the same factor based on the price of a seat in the row in front of it.
Using the team’s current arena charges, your work from PART A, and your understanding of sequences and series:
In: Computer Science
Write a program that allows the user to enter two integers and a character If the character is A, add the two integers If it is S, subtract the second integer from the first else multiply the integers Display the results of the arithmetic
In: Computer Science
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array.
Following is an example output 1, when the program execution is ./a.out 3 a b c 2
a b c aa ab ac ba bb bc ca cb cc
Following is an example output 2, when the program execution is ./a.out 2 a b 3
a b aa ab ba bb aaa aab aba abb baa bab bba bbb
In: Computer Science
To demonstrate the practical implementation of the public\private encryption, you have been asked to compete the following task.
i. Type the following message in a .txt file: “My student ID is : >
ii. Download the public key given in this assignment folder and encrypt your message with the same key using openssl. iii. Using openssl, generate RSA key pair (2048bits) in your computer.
my student id is 40926
In: Computer Science
Consider the following hypothetical microprocessor. Assume this processor uses 32-bit instructions. Assume the 32 bits are composed of an opcode of 7 bits and an address of 25 bits. Answer the questions below.
In: Computer Science
C Programing
How would i edit this code to have it return the cipher text.
void vigenereCipher(char* plainText, char* k){
int i;
char cipher;
int cipherValue;
int len = strlen(k);
//Loop through the length of the plain text string
for(i=0; i<strlen(plainText); i++){
//if the character is lowercase, where range is [97 -122]
if(islower(plainText[i]))
{
cipherValue = ( (int)plainText[i]-97 + (int)tolower(k[i % len])-97 ) % 26 +97;
cipher = (char)cipherValue;
}
else // Else it's upper case, where letter range is [65 - 90]
{
cipherValue = ( (int)plainText[i]-65 + (int)toupper(k[i % len])-65 ) % 26 +65;
cipher = (char)cipherValue;
}
//Print the ciphered character if it is alphanumeric (a letter)
if(isalpha(plainText[i]))
{
printf("%c", cipher);
}
else //if the character is not a letter then print the character (e.g. space)
{
printf("%c", plainText[i]);
}
}
}
In: Computer Science