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
MATLAB
Create a 2 × 3 matrix variable mat. Pass this matrix variable to each of the following functions and make sure you understand the result: flip, fliplr, flipud, and rot90. In how many different ways can you reshape it?
Note: (in addition to the functions listed, rotate the matrix 180 degrees clockwise)
In: Computer Science
C++
C++
Write a definition for a structure type for records for CDs. The record contains price and total number of songs, . Part of the problem is appropriate choices of type and member names.Then declare two variables of this structure. Write a function called GetData use the structure as function argument to ask the user to input the value from the keyboard for structure variables.
In: Computer Science
Write a method speedingTicket() that decides whether a driver should be given a ticket from a police officer. The method accepts three parameters: speed (i.e., car speed) as integer; limit (i.e., speed limit) as integer and a boolean named donut indicating whether or not the police officer has eaten a donut today. A police officer that has eaten a donut is happy, so he/she is less likely to give the driver a ticket.
Your method should display either “Give Ticket” or “No Ticket!” based on the following:
• TICKET: Driver’s speed is more than 20 over the speed limit, regardless of donut status.
• TICKET: Driver's speed is 5-20 over the speed limit and officer has not eaten a donut.
• NO TICKET: Driver's speed is 5-20 over the speed limit and officer has eaten a donut.
• NO TICKET: Driver’s speed is < 5 over the speed limit, regardless of donut status.
Sample Calls Output speedingTicket(58, 55, false) No Ticket!
speedingTicket(45, 30, false) Give Ticket
speedingTicket(100, 75, true) Give Ticket
speedingTicket(42, 35, true) No Ticket!
speedingTicket(30, 35, false) No Ticket! //write your method below including the method header
In: Computer Science
7. In order to improve the network performance and security, ACLs is recommended. Please explain what is the ACL ?
8. How can ACLs help with the required tasks?
9. What are the principles of applying ACLs?
10. How to block VLAN 10 to visit ISP? Please write down the ACL statement(s) accordingly
In: Computer Science
Develop a Java program that determines the gross pay for an employee. The company pays hourly rate for the first 40 hours worked by the employee and time and a half (1.5x hourly rate) for all hours worked in excess of 40. The user of your application will enter an employee name, shift (day or night) ,the number of hours worked for the week and their hourly rate. Your program should then calculate and display the employee’s name, regular pay, overtime pay, total gross pay and payperiod. PayPeriod is "Friday" for "day" shift and "Saturday" for "night" shift. Use class Scanner to input the data. Be sure to format output, so it is professionally displayed to your users.
Here is an example of pseudocode:
Start
Enter employee name
Enter employee shift (day/night)
Enter hours worked
Enter hourly pay rate
Calculate reg pay
if hours worked > 40 then
Calculate overtime pay
else
overtime = 0
Calculate total pay
Output employee name, reguldar pay, overtime pay, total pay
If day shift
output “Friday payperiod”
Else
output “Saturday payperiod”.
End.
In: Computer Science