The birthday paradox says that the probability (chance) that two people in a room will have the same birthday is more than half as long as n, the number of people in the room, is more than or equal to 23. This property is not really a paradox, but many people find it surprising. Write a Java program that generates 10 sets of 23 valid birthdays (ignore leap years). Check how many times the Birthday Paradox occurs and keep count of it. ONLY using arraylist please in java
In: Computer Science
#include <iostream>
#include "lib.hpp"
using namespace std;
int main() {
// declare the bool
bool a = true;
bool b= true;
//Print the Conjunction function
cout<<"\n\nConjunction Truth Table -"<<endl;
cout<< "\nP\tQ\t(P∧Q)" <<endl;
cout<< a <<"\t"<< b <<"\t"<< conjunction(a,b) <<endl;
cout<< a <<"\t"<< !b <<"\t"<< conjunction(a,!b) <<endl;
cout<< !a <<"\t"<< b <<"\t"<< conjunction(!a,b) <<endl;
cout<< !a <<"\t"<< !b <<"\t"<< conjunction(!a,!b)<<endl;
//Print the Disjunction function
cout<<"\n\nDisjunction Truth Table -"<<endl;
cout<< "\nP\tQ\t(PVQ)" <<endl;
cout<< a <<"\t"<< b <<"\t"<< disjunction(a,b) <<endl;
cout<< a <<"\t"<< !b <<"\t"<< disjunction(a,!b) <<endl;
cout<< !a <<"\t"<< b <<"\t"<< disjunction(!a,b) <<endl;
cout<< !a <<"\t"<< !b <<"\t"<< disjunction(!a,!b)<<endl;
//Print the ExclusiveOr function
cout<<"\n\nExclusiveOr Truth Table -"<<endl;
cout<< "\nP\tQ\t(P⊕Q)" <<endl;
cout<< a <<"\t"<< b <<"\t"<< exclusiveOr(a,b) <<endl;
cout<< a <<"\t"<< !b <<"\t"<< exclusiveOr(a,!b) <<endl;
cout<< !a <<"\t"<< b <<"\t"<< exclusiveOr(!a,b) <<endl;
cout<< !a <<"\t"<< !b <<"\t"<< exclusiveOr(!a,!b)<<endl;
//Print the Negation function
cout<<"\n\nNegation Truth Table -"<<endl;
cout<< "\nP\t~P" <<endl;
cout<< !a <<"\t" << negation(!a)<<endl;
cout<< a <<"\t" << negation(a) <<endl;
How can u do this code Using the enum keyword or a C++ class? To create a new type Boolean with the two values F and T defined.
In: Computer Science
Parallel Arrays
This question is in MindTap Cengage
Summary
In this lab, you use what you have learned about parallel arrays to complete a partially completed C++ program. The program should:
Either print the name and price for a coffee add-in from the Jumpin’ Jive Coffee Shop
Or it should print the message Sorry, we do not carry that.
Read the problem description carefully before you begin. The file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the program that searches for the name of the coffee add-in(s) and either prints the name and price of the add-in or prints the error message if the add-in is not found. Comments in the code tell you where to write your statements.
Instructions
Study the prewritten code to make sure you understand it.
Write the code that searches the array for the name of the add-in ordered by the customer.
Write the code that prints the name and price of the add-in or the error message, and then write the code that prints the cost of the total order.
Execute the program by clicking the "Run Code" button at the bottom of the screen. Use the following data:
Cream
Caramel
Whiskey
chocolate
Chocolate
Cinnamon
Vanilla
-----------------------------
This is what i have so far:
// JumpinJava.cpp - This program looks up and prints the names
and prices of coffee orders.
// Input: Interactive
// Output: Name and price of coffee orders or error message if
add-in is not found
#include <iostream>
#include <string>
using namespace std;
int main()
{
// Declare variables.
string addIn; // Add-in
ordered
const int NUM_ITEMS = 5; // Named constant
// Initialized array of add-ins
string addIns[] = {"Cream", "Cinnamon", "Chocolate",
"Amaretto", "Whiskey"};
// Initialized array of add-in prices
double addInPrices[] = {.89, .25, .59, 1.50,
1.75};
bool foundIt = false; // Flag
variable
int x;
// Loop control variable
double orderTotal = 2.00; // All orders start with a
2.00 charge
int findItem();
// Get user input
cout << "Enter coffee add-in or XXX to quit:
";
cin >> addIn;
// Write the rest of the program here.
findItem();
foundIt = false
x = 0
while(x <
NUM_ITEMS)
if addIn = addIns[x]
foundIt = true
orderTotal = addInPrices[x]
endif
x = x + 1
endwhile
if(foundIt = true)
{
cout << "The price of" << addIns[x] << "is"
<< addInPrices[x] << "." << endl;
}
else
{
cout << "Sorry, we do not carry that." << endl;
}
return 0;
} // End of main()
In: Computer Science
JAVA
Write a test program that prompts the user to enter a series of integers and displays whether the series contains runLength consecutive same-valued elements. Your program’s main() must prompt the user to enter the input size - i.e., the number of values in the series, the number of consecutive same-valued elements to match, and the sequence of integer values to check. The return value indicates whether at least one run of runLength elements exists in values. Implement the test program as part of the NConsecutive class (the main() method is already in place at the end of the class).
I am looking for a fix of my current code for this question. My code executes the expected output, but it messes up with other outputs. For example, if I input this data:
Enter The Number of Values: 5
How many consecutive, same-valued elements should I look for?:
2
Enter 5 Numbers: 1 1 2 2 1 1
The list has no sequence of 2 consecutive same-valued
elements
The output I should get is "The list has at least 1 sequence of 2 consecutive same-valued elements"
EXPECTED OUTPUT:
Enter the number of values: 3
How many consecutive, same-valued elements should I look for?
3
Enter 3 numbers: 5 5 5
The list has at least one sequence of 3 consecutive same-valued
elements
Enter the number of values: 3
How many consecutive, same-valued elements should I look for?
4
Enter 3 numbers: 5 5 5
The list has no sequences of 4 consecutive same-valued elements
CURRENT CODE:
public static boolean hasNConsecutive( int[] values, int
runLength ) {
int count = 0;
for (int i = 0; i <
(values.length-1);i++)
{
if (values[i] ==
values[i + 1]) {
count++;
if(count == runLength)
break;
}
else {
count = 0;
}
}
if (count >= (runLength - 1))
return true;
else
return false ;
} // end hasNConsecutive()
public static void main( String[] args ) {
int x, runLength;
Scanner input = new
Scanner(System.in);
System.out.printf("Enter The Number
of Values: ");
x = input.nextInt();
int values[] = new int[x];
System.out.printf("How many
consecutive, same-valued elements should I look for?: ");
runLength = input.nextInt();
System.out.printf("Enter "+ x + "
Numbers: ");
for(int i = 0; i < x; i++)
{
values[i] =
input.nextInt();
}
input.close();
if(hasNConsecutive(values,runLength))
System.out.println("The list has at least one sequence of " +
runLength + " consecutive same-valued elements");
else
System.out.println("The list has no sequence of " + runLength + "
consecutive same-valued elements");
}
}
In: Computer Science
(2) Cite an example on how organizations like Google, Facebook, Youtube etc collect data for image identification, email classification, mature content and cyber bullying. (Give one example for each).
In: Computer Science
In C++
Having call-by-reference allows one to use storeback parameters, i.e., parameters whose values are transmitted back to their arguments. In this exercise, you are to write a program that provides several variations of a function that calculates the minimum of two values. Several of the functions also report whether the two values passed in were equal. The functions are all named min — they differ in their arguments and return values:
Call the file min.cpp. In the same file, write a main function demonstrating use of the above functions. The app should accept pairs of integers from the console (until eof), call each of the function sand print out the results using the format illustrated below:
Sample test run:
first number? 3 second number? 4 int min(x, y): The minimum of 3 and 4 is 3 bool min(x, y, min): The minimum of 3 and 4 is 3 int min(x, y, ok): The minimum of 3 and 4 is 3 void min(x, y, ok, min): The minimum of 3 and 4 is 3 first number? 5 second number? 2 int min(x, y): The minimum of 5 and 2 is 2 bool min(x, y, min): The minimum of 5 and 2 is 2 int min(x, y, ok): The minimum of 5 and 2 is 2 void min(x, y, ok, min): The minimum of 5 and 2 is 2 first number?
In: Computer Science
“Triangle Guessing” game in Python
The program accepts the lengths of three (3) sides of a triangle as input . The program output should indicate if the triangle is a right triangle, an acute triangle, or an obtuse triangle.
In: Computer Science
THIS PROGRAM HAS TO BE WRITTEN IN C
Single function to perform the parity computation on the input integer passed to this function. The output of the function is 0 if the input has even parity (that is, the number of 1s in the binary representation of the input is even) and 1 if the input has odd parity (that is, the number of 1s in the binary representation of the input is odd).
In: Computer Science
1) Alternative compiled code sequence using instructions in classes A, B, C. What is the average CPI of sequence 1 and sequence 2?
class A B C
CPI for class 3 4 6
IC in Sequence 1 6 12 10
IC in sequence 2 2 4 2
2) given the 8-bit binary number 1011 1110 (two's compliment, we will call this number N)
a) what is the hEX representation of N
b) what is the decimal value if N is an 8-bit 2's compliment signed number?(please write steps
c)what is the decimal value if N is an 8-bit unsigned number?
In: Computer Science
Do we have any online or offline tool to convert c and cpp programs into MIPS and Other assembly languges.. If yes Please share the all the available tools details and Provide One example of conversions. I will upvote for good answer
In: Computer Science
function
X=extractDWT(x_train,startS,endS,wStep,wRange)
% x_train = input signal
% startS = from second
% endS = end second
% wStep = overlapping
% wRange = window size
FS=128;
N=size(x_train,3);
sz=floor((endS-(startS+wRange))/wStep)+1;
X=zeros(sz*140,2);
cn=0;
for i=1:N
for sig=startS:wStep:endS-wRange
sW=sig*FS+1;
eW=(sig+wRange)*FS;
C3Sig=x_train(sW:eW,1,i);
C4Sig=x_train(sW:eW,3,i);
waveletFunction =
'db4';
waveletLevel=3;
[wCoe,L] =
wavedec(C3Sig,waveletLevel,waveletFunction);
C3D3 =
detcoef(wCoe,L,3); % Mu
[wCoe,L] =
wavedec(C4Sig,waveletLevel,waveletFunction);
C4D3 =
detcoef(wCoe,L,3); % Mu
cn=cn+1;
% Mean of the absolute
values
X(cn,1)=sum(C3D3.^2)/numel(C3D3);
X(cn,2)=sum(C4D3.^2)/numel(C4D3);
end
end
end
Need code explanation for above code?
In: Computer Science
SQL FORMAT (11-13 are completed and correct)
-- 11. what are the names of all students who have taken some
course? Don't show duplicates.
select distinct(name) from student where tot_cred > 0;
-- 12. what are the names of departments that offer 4-credit
courses? Don't list duplicates.
select distinct(dept_name) from course where credits=4;
-- 13. What are the names and IDs of all students who have
received an A in a computer science class?
select distinct(name), id from student natural join takes natural
join cours$
-- 14. How many B grades have been given to physics majors?
-- 15. What is the average total credits of students who have taken
CS-319?
-- 16. What is the average total credits of students who have taken
CS-101?
-- 17. What are the course IDs of courses taught by instructor
Katz?
-- 18. What are the course IDs of all courses offered by instructor
Crick's department?
-- 19. What is the course_id, semester, and year of sections of
computer science courses?
-- Don't show duplicates.
-- 20. What are the names of students who have taken a class taught
by instructor Srinivasan?
In: Computer Science
In: Computer Science
1. Write an if-else statement to describe an object. Print "Balloon" if isBalloon is true and isRed is false. Print "Red balloon" if isBalloon and isRed are both true. Print "Not a balloon" otherwise. End with newline.
import java.util.Scanner;
public class RedBalloon {
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
boolean isRed;
boolean isBalloon;
isRed = scnr.nextBoolean();
isBalloon = scnr.nextBoolean();
/* Your solution goes here */
}
}
2. Assign isTeenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign isTeenager with false.
import java.util.Scanner;
public class TeenagerDetector {
public static void main (String [] args) {
Scanner scnr = new
Scanner(System.in);
boolean isTeenager;
int kidAge;
kidAge = scnr.nextInt();
/* Your solution goes here */
if (isTeenager) {
System.out.println("Teen");
}
else {
System.out.println("Not teen");
}
}
}
In: Computer Science
Write a program that copies the contents of one file to a destination file. This program works by first prompting the user for the name of the source and destination files. Be sure to include all necessary error checking, including ensuring that the source file exists. Also, if available, you have to use Linux system calls and not standard C library functions in your program.
[Restrictions] For file handling operations, only use the open, close, read and write system calls. For other operations you can use the library functions. For every use of library function where system call was required, 2 marks will be deducted.
Following error situations must be taken care of in the code: File not present, read error, write error, close error, create error, return value of system calls.
In: Computer Science