In: Computer Science
In Java
INSTRUCTIONS Write a java program called InputValidation.java that will use Scanner to ask the computer user to enter his/her: • Name: a string representing the user’s first name • month of birthday: an integer representing the month of the user’s birthday • day of birthday: an integer representing the day of the user’s birthday • year of birthday: an integer representing the year of the user’s birthday Consider the following aspects that your program shall perform: VALIDATE USER’S INPUT • Validate user’s data: Every time your program request information from the user the month must be between 1 –12 o Certain months have 30 days and others have 31 days. Your program must check for these cases o the day must be a number between 1 – 31 depending on the month provided previously USER INTERACTION AND CASE HANDLING • The user is allowed to make five mistakes in total while entering his/her information. • Notice that the user will continue entering his/her information in a repeatable fashion. • if the user had five mistakes in total, a comment shall be displayed as follows: Hi , you entered five mistakes. Please contact your official ID and try again later. And your program shall terminate immediately1 . • If the user successfully provided the data correctly, then your program shall display a message: Thank you for entering correct data • Design a flowchart that represents the flow of information in your entire program. You can use Microsoft Visio to develop this diagram. 1 You can use the System.exit() to terminate your program. PROGRAM OUTPUT AND RESULTS • Based on the user’s input for his/her year, check if the year provided is considered to be a leap year or not. If the year the user entered is leap, then you should write a message specifying that this person was born in a leap year. • Finally write an output message based on the decision on the leap year or not. If the year provided was leap, your message shall have “were” if the year was not, it should be “were not”, as follows: FYI , you born in a leap year
In: Computer Science
USING C++ ONLY.
Please study the code posted below.
the goal is to rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same.
/**
* Queue implementation using linked list C style
implementation ( no OOP).
*/
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <iostream>
#define CAPACITY 100 // Queue max capacity
using namespace std;
/** Queue structure definition */
struct QueueType
{
int data;
struct QueueType * next;
};
/** Queue size */
unsigned int size = 0;
int enqueue(QueueType * &rear, QueueType * &front,
int data);
int dequeue(QueueType * &front);
int getRear(QueueType * &rear);
int getFront(QueueType * &front);
void display(QueueType * front);
int isEmpty();
int isFull();
string prepMenu();
int main()
{
int option, data;
QueueType *rear, *front;
rear = NULL;
front = NULL;
string menu = prepMenu();
cout << menu << endl;
cin >> option;
while (option !=7)
{
switch (option)
{
case 1:
cout << "\nEnter data to enqueue (-99 to stop):
";
cin >> data;
while ( data != -99)
{
/// Enqueue function returns 1 on success
/// otherwise 0
if (enqueue(rear, front, data))
cout << "Element added to queue.";
else
cout << "Queue is full." <<
endl;
cout << "\nEnter data to enqueue (-99 to stop):
";
cin >> data;
}
break;
case 2:
data = dequeue(front);
/// on success dequeue returns element
removed
/// otherwise returns INT_MIN
if (data == INT_MIN)
cout << "Queue is empty."<<
endl;
else
cout << "Data => " << data <<
endl;
break;
case 3:
/// isEmpty() function returns 1 if queue is
emtpy
/// otherwise returns 0
if (isEmpty())
cout << "Queue is empty."<<
endl;
else
cout << "Queue size => "<< size <<
endl;
break;
case 4:
data = getRear(rear);
if (data == INT_MIN)
cout << "Queue is empty." <<
endl;
else
cout << "Rear => " << data <<
endl;
break;
case 5:
data = getFront(front);
if (data == INT_MIN)
cout <<"Queue is empty."<< endl;
else
cout <<"Front => " << data <<
endl;
break;
case 6:
display(front);
break;
default:
cout <<"Invalid choice, please input number between
(0-5).\n";
break;
}
cout <<"\n\n";
cout << menu<< endl;
cin >> option;
}
}
/**
* Enqueues/Insert an element at the rear of a
queue.
* Function returns 1 on success otherwise returns
0.
*/
int enqueue(QueueType * &rear, QueueType * &front,
int data)
{
QueueType * newNode = NULL;
/// Check queue out of capacity error
if (isFull())
{
return 0;
}
/// Create a new node of queue type
newNode = new QueueType;
/// Assign data to new node
newNode->data = data;
/// Initially new node does not point
anything
newNode->next = NULL;
/// Link new node with existing last node
if ( (rear) )
{
rear->next = newNode;
}
/// Make sure newly created node is at rear
rear = newNode;
/// Link first node to front if its NULL
if ( !( front) )
{
front = rear;
}
/// Increment quque size
size++;
return 1;
}
/**
* Dequeues/Removes an element from front of the
queue.
* It returns the element on success otherwise
returns
* INT_MIN as error code.
*/
int dequeue(QueueType * &front)
{
QueueType *toDequque = NULL;
int data = INT_MIN;
// Queue empty error
if (isEmpty())
{
return INT_MIN;
}
/// Get element and data to dequeue
toDequque = front;
data = toDequque->data;
/// Move front ahead
front = (front)->next;
/// Decrement size
size--;
/// Clear dequeued element from memory
free(toDequque);
return data;
}
/**
* Gets, element at rear of the queue. It returns the
element
* at rear of the queue on success otherwise return INT_MIN
as
* error code.
*/
int getRear(QueueType * & rear)
{
// Return INT_MIN if queue is empty otherwise
rear.
return (isEmpty())
? INT_MIN
: rear->data;
}
/**
* Gets, element at front of the queue. It returns the
element
* at front of the queue on success otherwise return INT_MIN
as
* error code.
*/
int getFront(QueueType * &front)
{
// Return INT_MIN if queue is empty otherwise
front.
return (isEmpty())
? INT_MIN
: front->data;
}
/**
* Checks, if queue is empty or not.
*/
int isEmpty()
{
return (size <= 0);
}
/**
* Checks, if queue is within the maximum queue
capacity.
*/
int isFull()
{
return (size > CAPACITY);
}
string prepMenu()
{
string menu = "";
menu+= "
\n-------------------------------------------------------------------\n";
menu+= "1.Enqueue 2.Dequeue 3.Size 4.Get Rear 5.Get Front
6.Display 7.Exit\n";
menu+=
"----------------------------------------------------------------------\n";
menu+= "Select an option: ";
return menu;
}
void display(QueueType * front)
{
for ( QueueType *t = front; t !=NULL; t =
t->next)
cout <<t->data << " ";
cout << endl << endl;
}
please provide comments in the code where appropriate, thank you!
In: Computer Science
3.There is two types of communications network write them. What is the main Characteristic of WANs , Write the main use LANs Network
In: Computer Science
Design two function templates as follows: -
First function template will be used to sort arrays of different data types in either descending or ascending order. This function template is required to have the following parameters: an array of a generic type, an integer representing the size of the array, and a character representing the order of sorting (i.e., ascending or descending). The last argument (i.e., the order of sorting) is required to be a default argument. The default order of sorting should be ascending.
- Second function template will be used to display an array. This function template is required to have two parameters: an array of a generic type and an integer representing the size of the array.
Design the main program that can be used to test both function templates above. The program should create the two dynamic arrays one of which will store integer values, while the other array will store character values. The size of both arrays will be determined at run time, i.e. entered by the user. The requested order of sorting (i.e., ascending or descending) for each array will also be obtained from the user at run time. The values stored in both arrays will be generated by the random numbers generator (i.e., srand() and rand() library functions could be used). Please note that the random characters' ASCII values should be in the range from 33 to 126, while the random integer numbers should be in the range from 1 to 100. The program will call both templates to sort arrays in the requested order and display both arrays before and after sorting. It is required to include all necessary error checking which includes the code to prevent any "garbage input" from the user as well as the code to prevent the memory allocation error.
In: Computer Science
You have information about recent sales that you want to use for testing the database. 1. Create the tables for the data provided. The tables should include the primary and foreign keys. Provide the SQL statements. 2. Insert the data into the tables. Provide the SQL statements. 3. Show the contents of each table. Provide the SQL statements.
Customer Table Customer ID, Last Name, First Name, Street Address, City, State, Zip Code, Current Balance, Credit Limit, Sales Rep. ID Sales Representatives Table Sales Rep ID, Last Name, First Name, Street Address, City, State, Zip, Region, Region Description, Total Commission, Commission Rate Orders Table Order ID, Order Date, Customer, Shipping Date, Order Lines Order ID, Part ID, Number Ordered, Quoted Price Part Table Part ID, Part Description, Units on Hand, Class, Warehouse Number, Unit Price
Please show all work
In: Computer Science
1.6 List and briefly define the fundamental security design principles.
1.7 Explain the difference between an attack surface and an attack tree.
In: Computer Science
Why does LINUX OS have limited graphics and mostly utilize the CLI?
In: Computer Science
I am taking a Data Structures and Program Design class. BUT, I am having trouble getting access to the vectors so that I can compare the guesses with the random numbers. I’ve been working on this for several days and don't feel any closer to a solution and could really use some help as I really don't know how to get this to work. Thank you!
The assignment is:
Design an ADT for a one-person guessing game that chooses 4 random integers in the range from 1 to 9 and asks the user to guess them. The same integer might be chosen more than once. For example, the game might choose the following four integers that range from 1 to 9: 4, 6, 1, 6. The following interaction could occur between the user and the game:
Enter your guesses for the 4 integers in the range from 1 to 9 that have been selected:
User Input: 1 2 3 4
2 of your guesses are correct. Guess again.
User Input: 2 4 6 8
2 of your guesses are correct. Guess again.
User Input: 1 4 6 6
You are correct! Play again? No
Good-bye!
Submit header file guess.h, implementation file guess.cpp, main function file main.cpp You need to include a makefile, and Readme file (see Programming Guidelines).
My code is:
---------------------------------main.cpp----------------------------------------
#include <iostream> // needed for using cin/cou statements
#include <string> // needed for using string type
#include <fstream> // needed for using files
#include <ctime> // Enables use of time() function
#include "guess.h"
using namespace std;
int main() {
bool play = true;
string answer;
int randomNumsToGuess[3];
int playerGuesses[4];
srand(time(0));
int matches = 0;
bool match = false;
Guess g1;
do {
cout << "Begin" << endl; //just for following along
do {
cout << "Enter your first guess" << endl;
cin >> playerGuesses[0];
cin.ignore();
cout << "Enter your second guess" << endl;
cin >> playerGuesses[1];
cin.ignore();
cout << "Enter your third guess" << endl;
cin >> playerGuesses[2];
cin.ignore();
cout << "Enter your fourth guess" << endl;
cin >> playerGuesses[3];
cin.ignore();
Guess (playerGuesses[0], playerGuesses[1], playerGuesses[2], playerGuesses[3]);
cout << "Sitting just before loop" << endl;
for (int i = 0; i < 4; i++) {
cout << "Entered first loop" << endl;
for (int j = 0; j < 4; j++) {
cout << "Entered second loop" << endl;
//***** HERE IS WHERE I ERROR OUR ******
if (g1.getVecGuesses(i) == g1.getVecRandomCopy(i)) {
matches = matches + 1;
//cout << "Match at playerGuess " << playerGuesses[i] << "and randomNum" << vecRandomCopy[j] << endl; //used during testing
g1.setVecGuesses(i);
g1.setVecRandomCopy(j);
//vecGuesses[i] = -1;
//vecRandomCopy[j] = -2;
//gameOver = true;
cout << "Matches: " << matches << endl;
}
cout << "Number of correct matches: " << matches << endl;
}
}
if (matches == 3) {
cout << "Congratulations! You guessed all three random numbers!" << endl;
} else {
cout << "Try again" << endl;
}
} while (matches != 3);
matches = 0;
cout <<"Would you like to play again?" << endl;
cout << "Enter Y for yes or N for no." << endl;
cin >> answer;
cin.ignore();
if (answer == "Y") {
play = true;
}
else {
play = false;
cout << "Thanks for playing!" << endl;
}
} while (play == true);
return 0;
};
-------------------------------Guess.h-------------------------------------------
//
// Created by craig on 9/4/2019.
//
#ifndef DSPD_HW1_GUESS_H
#define DSPD_HW1_GUESS_H
#include <vector>
using namespace std;
class Guess{
private:
vector <int> vecRandom;
vector <int> vecRandomCopy;
vector <int> vecGuesses;
int randomNum;
int matches = 0;
public:
Guess();
Guess(int a, int b, int c, int d);
void Matches (vector<int> vecRandomCopy, vector<int> vecGuesses);
void showVecGuesses(vector<int>);
//might need to Guess::vecGuesses[x] = -1;
void setVecGuesses (int x) {
vecGuesses[x] = -1;}
//void setVecGuesses (vector<int> _vecGuesses(int x)) {vecGuesses[x] = _vecGuesses[x];}
void setVecRandomCopy (int y) {
vecRandomCopy[y] = -2;}
/*void displayVecContents (){
for (unsigned int i=0; i<vecGuesses.size(); i++ )
cout << "Guesses " << vecGuesses[i] << endl;
}
*/
int getVecGuesses (int x) {
cout << "TEST " << vecGuesses[x];
return vecGuesses[x];}
int getVecRandomCopy (int y) {
return vecRandomCopy[y];}
int Matches (vector<Guess> & ) {
cout << "Testing Matches" << endl;
}
};
#endif //DSPD_HW1_GUESS_H
--------------------------guess.cpp --------------------------------------
//
// Created by craig on 9/4/2019.
//
#include <iostream> // needed for using cin/cou statements
#include <string> // needed for using string type
#include <fstream> // needed for using files
#include <ctime> // Enables use of time() function
#include <vector>
#include "guess.h"
using namespace std;
Guess::Guess() {//default constructor, fills with random numbers
for (int i = 0; i < 4; i++) {
randomNum = (rand() % 9)+1;
vecRandom.push_back(randomNum);
cout << "Random number " << i + 1 << ": " << vecRandom[i] << endl;
}
for (int i=0; i < 4; i++) { //creates a copy of the random numbers so I can manipulate it without
//losing the original random numbers
vecRandomCopy = vecRandom;
cout << "Random number copy " << i + 1 << ": " << vecRandomCopy[i] << endl;
}
}
Guess::Guess (int a, int b, int c, int d){ //constructor for user guesses
vecGuesses.push_back(a);
vecGuesses.push_back(b);
vecGuesses.push_back(c);
vecGuesses.push_back(d);
cout << "You Guessed: ";
for (int i = 0; i < 4; i++) {
cout << " " << vecGuesses[i];
}
cout << endl;
}
void showVecGuesses(vector<int> _vecGuesses){
for (int i=0; i<4; i++){
cout << "TESTING SHOW VEC GUESSES" << endl;
cout << _vecGuesses[i] << endl;
}
}
void Matches (vector<int> _vecRandomCopy, vector<int> _vecGuesses){
cout << "TESTING: do we get into matches?" << endl;
}
In: Computer Science
Principles and characteristics of a successful IG program. Please identify these Principles and select one that you feel is the most important and explain, in your own words, why you feel this principle is the most important.
In: Computer Science
I HAVE THIS PROBLEM:
Create a new Project and name it - InClassParticipation3
Get up to 5 inputs from the user. The user must enter at least 1
number.
After the first input, ask them if they would like to input another
number, if they say 'yes' get the provided input and multiply it to
the other inputs provided by the user.
If the user says 'no', do not prompt them to input anymore numbers
and then figure out if the number is divisible by 3, 5, both 3 AND
5, or none of the provided options.
If the number is divisible by 3, output the number and then
'YAY'.
If the number is divisible by 5, output the number and then
'ME'.
If the number is divisible by both 3 and 5, output the number and
then 'YAYME!!'.
If it is not divisible by either 3 or 5, simply just output the
number.
**THE CODE I HAVE WRITTEN SO FAR IS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace InClassParticipation3_1
{
class Program
{
static void Main(string[] args)
{
double val1, val2, val3, val4, val5;
string answer;
int total;
Console.WriteLine("Please enter a number.");
val1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Would you like to enter another value? Answer
yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the second value.");
val2 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? Answer
yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the third value: ");
val3 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? Answer
yes or no.");
answer = Console.ReadLine();
if (answer == "yes")
{
Console.WriteLine("Enter the fourth value: ");
val4 = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Would you like to enter another value? This is
the last one!! Answer yes or no.");
answer = Console.ReadLine();
Console.WriteLine("Enter the fifth value: ");
val5 = Convert.ToInt32(Console.ReadLine());
if (total % 3 == 0 && total %
5 == 0) **THE ERROR IS HERE ON THE "total" IN THE FIRST
"If" STATEMENT.???
{
Console.WriteLine("YAYME!!");
}
else if (total % 3 == 0)
{
Console.WriteLine("YAY");
}
else if (total % 3 == 0)
{
Console.WriteLine("ME");
}
else
{
Console.WriteLine(total);
}
// Console.WriteLine("The total of the three values you entered is:
" + sum);
//Console.WriteLine("The total of the three values you entered is:
" + mulpSum);
//Console.ReadKey();
}
}
}
**PLEASE HELP ME FIGURE OUT WHAT I AM DOING WRONG!!
In: Computer Science
Create a program that will ask the user to choose their order from a simple menu. Customers first choose from three types of dishes: Sandwiches/wraps, Rice Meals, or Noodles. They can type in 1, 2, or 3 to select the type then, they choose a specific dish as shown below. Confirm their order by displaying it on the screen after they make their selection. 1. Sandwiches/wraps Hamburger Chicken shawarma 2. Rice meals Arroz con pollo Chana masala 3. Noodles Chow mein Pasta al pomodoro Which variation of the if statement would best fit the requirements (if, if-else, if-else-if chain, nested if)? Create the complete C++ program.
In: Computer Science
You are the web master for the Republican Party National Committee. Prepare a risk assessment analysis for your website. 300 words.
Some questions to consider: Who is likely to attack your site? When are attacks likely to occur? What sort of attacks might take place? How can you best minimize attacks and protect the integrity of your site?
In: Computer Science
I'm having trouble printing a fibonacci sequence using pointers with malloc's to get this output.
now printing with pointers:
0 1 1 2 3 5 8 13 21 34 55 89
Here's my code:
#include <stdio.h>
#include <stdlib.h>
void fib1(int a[]);
void fib2(int* a);
}
int main() {
int arr[2] = {0,1};
int *pointer;
arr[0]=0;
arr[1]=1;
fib1(arr);
return 0;
}
void fib1(int a[]){
printf("printing with arrays:\n");
for(int i=0; i<6; i++){
printf("%d %d ", a[0],a[1]);
a[0] = a[0] + a[1];
a[1] = a[0] + a[1];
}
printf("\n\n");
}
void fib2(int* a){
printf("printing with pointers:\n");
for(int i=0; i<6; i++){
printf("%d %d ", a,a);
}
}
In: Computer Science
An abs-sorted array is an array of numbers in which |A[i]| <= |A[j]| whenever i < j.
For example, the array A = [-49, 75, 103, -147, 164, -197, -238, 314, 348, -422],
though not sorted in the standard sense, is abs-sorted. Design an algorithm that
takes an abs-sorted array A and a number k, and returns a pair of indices of elements
in A that sum up to k. For example if k = 167 your algorithm should output (3, 7).
Output (-1, -1) if the is no such pair.
In: Computer Science