A bag of cookies contains 40 cookies. The calorie information printed on the bag claims that there are 8 servings in each bag and that a single serving equals 300 calories. Design and write a C++ program that prompts your user for the number of cookies that he or she ate and then displays the calories they consumed.
Use variables to represent the given information, such as the number of cookies in each bag and the number of calories in each serving. Compose statements using the given variables to calculate the number of calories in each cookie. Use the number of cookies and the number of calories per cookie to determine how many calories were consumed. The use of magic is not permitted in computer programming. You, as the programmer must compose steps that store given information in variables and then use these variables to determine values such as the number of calories in each cookie.
CODE IN C++
In: Computer Science
1.
Assuming A equals the binary value 10101010 and B equals the binary value 11110000, the result of the bitwise-OR of A with B is?
Just enter the 8-bit binary number that represents the result of the operation. Do not add any spaces, decimal points, commas, or base-2 subscript. Do not delete leading zeros.
2.
Assuming A equals the binary value 10101010 and B equals the binary value 11110000, the result of the bitwise-XOR of A with B is?
Just enter the 8-bit binary number that represents the result of the operation. Do not add any spaces, decimal points, commas, or base-2 subscript. Do not delete leading zeros.
3.
Assuming A equals the binary value 11110000, the result of the bitwise inverse of A is?
Just enter the 8-bit binary number that represents the result of the operation. Do not add any spaces, decimal points, commas, or base-2 subscript. Do not delete leading zeros.
In: Computer Science
In: Computer Science
1. Multi-layer BP neural networks have no proof of converging to an optimal solution. Is this true? If it is, then why do we bother to use them?
1. What is the fundamental equation that guides changes to a weight wij in a BP network. Describe its components.
In: Computer Science
1. Proveif ?∈?,then1+(−1)!(2?−1)is a multiple of four
2. If?={∅,{∅}}, which of the following statements is true:
a.∅⊆?
b.{∅}⊆?
c.{∅}∈?
3. Provide a grammar for all bit strings that start with exactly one zero followed by even number of 1’s.
In: Computer Science
Problem1: In this problem we will ask the use to enter a value greater than 1,000 and less than 1,000,000 without a comma and the program will add the comma.
In: Computer Science
This is in java, thank you!
Problem2: In this problem you ask the user for a month and day. You will then calculate the season based on the month and day.
In: Computer Science
In Python
The following code is intentionally done in poor style but runs
as intended.
def main():
c = 10
print("Welcome to Roderick's Chikkin and Gravy")
e = False
while not e:
x = input("Would you like some chikkin?")
if x == "Y" or x == "y":
c = f(c)
else:
e = True
if c == 0:
e = True
print("I hope you enjoyed your chikkin!")
def f(c):
if c > 0:
print("Got you some chikkin! Enjoy")
return c-1
else:
print("No chikkin left. Sorry")
return 0
main()
1.Fix it *then* add the functions mentioned (Including totally
deleting these comments at the top and replacing them with)
What should be here as well as changing the repl name!?
2.Fix the style of this program so it is clear what it is doing.
3.Add to the code so that, if you want chikkin, you are asked if you want gravy. If you say yes, the (only) output for that order should be, "You get some chikkin and gravy then!" If not, it should give the same output as the original program. In both cases, it will then ask you again if you want any chikkin.
4.Add to the code so that, if you want chikkin, you are asked if you want gravy. If you say yes, the (only) output for that order should be, "You get some chikkin and gravy then!" If not, it should give the same output as the original program. In both cases, it will then ask you again if you want any chikkin. (You can do whatever you would like to get this to happen - adding a new function is not required but don't delete the old function entirely). Assume you have infinite gravy so no tracking how much gravy there is.
5.Write a simple function named startingChikkin() that has no parameters and just asks the user for how much chikkin we start with. If the user types a positive integer, then return that value. If not, prompt again repeatedly until they enter a positive integer which you then return (see earlier sections on input validation) - the loop should be inside of your function. Call startingChikkin() at the start of the main() program and store the value returned into whatever you called your variable for tracking the number of chikkins left.
In: Computer Science
Question: How would British Airlines or how did they recover the trust of their passengers and after that major hack? Did this issue lead to any financial loss? Why were they not prepared to combat this earlier on?
Please answer this question
Thnks
In: Computer Science
Design the Use Case Diagram and the test cases for Online Mobile Store
Use Cases Phase II description
Example: Online Computer Store Requirement
1 – Laptops Requirement
2 - Desktops Requirement
3 - Mainframes
Use Cases Testing phase 2 Requirement
1 - Laptops - Test case Requirement
2 - Desktops Requirement
3 - Mainframes
In: Computer Science
In python.
Write a program that takes 2 string inputs and calculates the Hamming Distance. Hamming distance between two strings is the number of positions at which the corresponding symbols are different.
The program should output an integer representing this distance.
For example
a = XXWWZZ
b = ZZWWXX
answer = 4
More examples:
"Phone" and "PHOONE" = 3
"God" and "Dog" = 2
"Dog" and "House" = 4
In: Computer Science
urgent!!! code in c++
- cannot use vector
- please use inheritance
-please identify the .h and .cpp files and add tester program and screenshot of output!
-please complete all parts I will upvote thank you!!!
Define the following classes to manage the booking of patients in a medical clinic.
a) Define a class Date that has the following integer data
members: month, day and year.
b) Define a class AppointmentTime that has the following data
members: day (string), hour (int) and minute (int).
c) Define a class Patient with the following data members:
The name of the patient as a standard library string.
The date of birth of the patient (from part a).
Medical insurance number of the patient as a standard library string.
Name of the doctor for the appointment.
Day and time of the appointment (from part b).
A patient may have a single doctor’s appointment each week.
The name of the doctor as a standard library string.
The date of birth of the doctor (from part a).
A two-dimensional string pointer array of 12-by-5 that shows the appointments of that doctor. The appointment durations are 30 mins and they always begin on the hour or half hour. Doctors see patients Monday to Friday during 9.00-12.00 and 14.00-17.00. This array is initialized to empty strings to indicate that at the beginning all the appointments are available. When an appointment is given a pointer to the medical insurance of the patient is stored at that location.
A Patient object from part (b).
Doctor’s name.
The day that appointment is requested as a standard library string (Monday to Friday).
f) Define a class ClinicManager with the following data members:
An array of pointers to the Patient objects of size 200.
An array of pointers to the Doctor objects of size 20.
An integer variable that counts total number of patient
appointments given by the clinic in a week.
At least the following member functions should be provided,
A member function that receives a patient object and inserts it
to the Patient pointer array. It will check if the patient is
already in the array to prevent multiple copies of the patient
object in the array.
A member function that receives a doctor object and inserts to the
Doctor pointer array.
A member function that processes appointment requests. The function
will receive an AppointmentRequest object, then will check the
requested doctor’s schedule to determine if the appointment can be
made. If the appointment can be scheduled it will store the medical
insurance of the patient in the appointment array of that doctor.
It will create an AppointmentTime object from part b). Then, it
will find the patient in the Patient pointer array and store the
doctor’s name and AppointmentTime object in the patient object in
the Patient pointer array. Finally, the member function will return
the AppointmentTime object. If the doctor is already fully booked
on that day this object should should return zeros for the
appointment time.
A member function that cancels an appointment, receives doctor’s
name and medical insurance of the patient. Then it removes the
appointment both from the doctor’s schedule and from the
patient.
A member function that receives a doctor’s name as a parameter and
prints name and medical insurance number of all the patients that
have booked an appointment with that doctor.
g) Write a driver program that demonstrate the functionality of your program including:
- Creates a ClinicManager object
- Creates doctor objects and calls to the doctor insert member function.
- Creates Patient and AppointmentRequest objects and calls to the member functions that
processes the appointments, then outputs the time of the appointment.
§ You must enforce encapsulation by keeping all data members private.
§ You need to make sure that your classes are well defined using the various concepts
seen in the class.
§ Provide needed set/get functions for the data members.
§ Objects should be created dynamically and must be deleted when no longer needed. There should be an output statement confirming the deletion of an object from the destructor function.
In: Computer Science
C++
Implement the array based Binary Heap data structure as discussed in class. This structure should have a couple of constructures (default constructor, and a constructor that takes an array pointer and a size), a method for inserting items into the heap, a method for removing items from the heap, and a method that returns the number of items currently stored in the heap. This implementation should be templated so that it can store any type of data (you may assume that the <, >, ==, <=, and >= operators are implemented for the type of data being stored). The constructor that takes parameters should set the data structure to use the array passed in as the array for the heap, and then "insert" each item in the array to the heap. You should also throw exceptions where it makes sense to and for the insert method, you should handle the overflow case by increasing the size of the storage. Remember this should be implemented using Object Oriented Programming principles
In: Computer Science
Using Pseudocode: Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents.
In: Computer Science
C++
existing code
#include "ArrayBag.hpp"
#include <iostream>
/****************************************************** Public Methods *****************************************************/
/* Default Constructor */
template <typename ItemType>
ArrayBag<ItemType>::ArrayBag() : item_count_(0) { //
initializer list
} // end default constructor
template <typename ItemType>
int ArrayBag<ItemType>::getCurrentSize() const {
return item_count_;
}
template <typename ItemType>
bool ArrayBag<ItemType>::isEmpty() const {
return item_count_ == 0;
}
template <typename ItemType>
bool ArrayBag<ItemType>::add(const ItemType &new_entry)
{
bool has_room_to_add = (item_count_ < DEFAULT_CAPACITY);
if (has_room_to_add) {
items_[item_count_] = new_entry;
item_count_++;
} // end if
return has_room_to_add;
} // end add
template <typename ItemType>
bool ArrayBag<ItemType>::remove(const ItemType &an_entry)
{
int located_index = getIndexOf(an_entry);
bool can_remove_item = !isEmpty() && (located_index >
-1);
if (can_remove_item) {
item_count_--;
items_[located_index] = items_[item_count_]; // copy
// last item in place of item to be removed
} // end if
return can_remove_item;
} // end remove
template <typename ItemType>
void ArrayBag<ItemType>::clear() {
item_count_ = 0;
}
template <typename ItemType>
bool ArrayBag<ItemType>::contains(const ItemType
&an_entry) const {
return getIndexOf(an_entry) > -1;
} // end contains
template <typename ItemType>
int ArrayBag<ItemType>::getFrequencyOf(const ItemType
&an_entry) const {
int frequency = 0;
int current_index = 0; // array index currently
// being inspected
while (current_index < item_count_) {
if (items_[current_index] == an_entry) {
frequency++;
} // end if
current_index++; // increment to next entry
} // end while
return frequency;
} //end getFrequencyOf
template <typename ItemType>
void ArrayBag<ItemType>::operator+=(const
ArrayBag<ItemType> &a_bag) {
}
template <typename ItemType>
void ArrayBag<ItemType>::operator-=(const
ArrayBag<ItemType> &a_bag) {
}
template <typename ItemType>
void ArrayBag<ItemType>::operator/=(const
ArrayBag<ItemType> &a_bag) {
}
template <typename ItemType>
bool ArrayBag<ItemType>::operator==(const
ArrayBag<ItemType> &a_bag) {
}
template <typename ItemType>
bool ArrayBag<ItemType>::operator!=(const
ArrayBag<ItemType> &a_bag) {
}
/***************************************************** Private Methods *****************************************************/
template <typename ItemType>
int ArrayBag<ItemType>::getIndexOf(const ItemType
&target) const {
bool found = false;
int result = -1;
int search_index = 0;
while (!found && (search_index < item_count_)) { // if the bag is empty, item count is zero, so loop is skipped
if (items_[search_index] == target) {
found = true;
result = search_index;
}
else {
search_index++;
} // end if
} // end while
return result;
} // end getIndexOf
Define the following operator overloads in ArrayBag.hpp and implement them accordingly in ArrayBag.cpp.
/** Implements Set Union. The union of two sets A and B is the set of elements, which are in A, in B, or in both A and B. @param a_bag to be combined with the contents of this (the calling) bag @post adds as many items from a_bag as space allows lhs += rhs, the left hand side (the calling side) of the operator will be modified. **/ void operator+=(const ArrayBag &a_bag); /** Implements Set Difference The (set) difference between two sets A and B is the set that consists of the elements in A which are not elements of B. @param a_bag to be subtracted from this (the calling) bag @post removes all the data from items_ that is also found in a_bag lhs -= rhs, the left hand side (the calling side) of the operator will be modified, remove elements from lhs that are also elements of the rhs (a_bag). **/ void operator-=(const ArrayBag &a_bag); /** Implements Set Intersection The intersection of two sets A and B is the set that consists of the elements that are in both A and B. @param a_bag to be intersected with this (the calling) bag @post items_ no longer contains elements not found in a_bag lhs /= rhs, the left hand side (the calling side) of the operator will be modified, remove elements from lhs that are NOT elements of the rhs (a_bag). **/ void operator/=(const ArrayBag &a_bag); /** Implements Equal Comparison Two ArrayBags are equal to each other if they contain the same elements the order of the elements do not matter. @param a_bag to be compared with this (the calling) bag @return true if the two bags contain the same elements, false otherwise Note that in order for two bags to be equal the must be of equal sizes. **/ bool operator==(const ArrayBag &a_bag); /** Implements Not Equal Comparison Opposite of the == operator, if two bags have at least one element different they are not equal @param a_bag to be compared with this (the calling) bag @return true if two bags have a differing element, false if they are equal In this case we can be sure that two arrays are not equal if they have different sizes. **/ bool operator!=(const ArrayBag &a_bag);
In: Computer Science