(1) Create three files to submit:
Build the ItemToPurchase class with the following specifications:
(2) In main(), prompt the user for two items and create two
objects of the ItemToPurchase class. Before prompting for the
second item, call cin.ignore() to allow the user
to input a new string. (2 pts)
Ex:
Item 1 Enter the item name: Chocolate Chips Enter the item price: 3 Enter the item quantity: 1 Item 2 Enter the item name: Bottled Water Enter the item price: 1 Enter the item quantity: 10
(3) Add the costs of the two items together and output the total
cost. (2 pts)
Ex:
TOTAL COST Chocolate Chips 1 @ $3 = $3 Bottled Water 10 @ $1 = $10 Total: $13
_____________________________________________________________________________________________
given started code:
main.cpp:
#include <iostream>
using namespace std;
#include "ItemToPurchase.h"
int main() {
/* Type your code here */
return 0;
}
__________________________________________________________________________________________
ItemToPurchase.cpp
#include <iostream>
using namespace std;
#include "ItemToPurchase.h"
/* Type your code here */
___________________________________________________________________________________________
ItemToPurchase.h
#ifndef ITEM_TO_PURCHASE_H
#define ITEM_TO_PURCHASE_H
#include <string>
using namespace std;
/* Type your code here */
#endif
In: Computer Science
Write -127 as 8 bit signed binary number both using 2'complement and sign/magnitude notation.
In: Computer Science
I know the code isn't here nut please answer as much as you can thanks!
it is qt creator c++
Question 1
Which of the following is a correct description of ItemList ?
Question 2
Which of the following is true about the menu option, Open?
Question 3
What is meant by separating model and view?
Question 4
In the given project, how do the view classes access the data in the model classes?
Question 5
Which of the following is a view class in the given project?
Question 6
Why is QActionGroup used in this project?
Question 7
Which of the following is a model class in the given project?
Question 8
After making necessary changes so that the images appear on the window (as required for question 2) which of the following is correct after the images are displayed on the window?
Question 9
Which is the correct description of line 83 (*i=*j) in mymainwindow.cpp?
Question 10
Which of the following is incorrect about ItemDialog?
Question 11
Which of the following is incorrect about the project?
Question 12
What does the icon R stand for?
Question 13
When the user initiates the Save option, which of the following is correct?
Question 14
Assume that the user initiates Add option and fills in all the fields using the Add ItemDialog. How does the application handle the data entered by the user, if the bar code provided already exists?
Question 15
Assume you need to implement a function named getDescription() in ItemList that accepts a bar code and returns the description of the item that matches the bar code. Which of the following is the correct implementation of a function getDescription()?
• A. QString ItemList::getDescription(QString b) const{
return list.value(b)->description;
}
• B. QString ItemList::getDescription(QString b) const{
return list.key(b)->description;
}
• C. QString ItemList::getDescription(QString b) const{
return list.value(b)->getDescription();
}
• D. QString ItemList::getDescription(QString b) const{
return list.key(b)->getDescription();
Question 16
Which of the following is incorrect about ItemReader?
• A. ItemReader performs error checking of data read from the file
• B. It can only create Item objects
• C. It is designed to read the data of items from a file
• D. It creates Item objects if the data is formatted in a specific format
Question 17
The output window should display images, which are included in the icons folder. What is needed to be done for the images to appear on the output window without making any changes to the given project?
Question 18
Which of the following is incorrect about isValidBarCode() of Item?
• A. It can be invoked without an object of Item
• B. It can be invoked on an object of Item
• C. It is invoked before a new item is added to the list of applications
• D. It is designed to work with the bar code in its parameter
Question 19
What does the class Item represent?
• A. It represents an expired item in a shop
• B. It represents items in a shop
• C. It represents transactions in a shop
• D. It represents all items that are out of stock in a shop
Question 20
In some cases the main window displays the titles Barcode, Description, Stock and Price when there are no items loaded in the application. How can you ensure that these titles only appear if there are items loaded in the application?
• A. Remove the following statement from mymainwindow.cpp:
textEdit->textCursor().insertText(QString("%1\t%2\t%3\t%4\n").
arg("Barcode", 13).arg("Description", 20) .arg("Stock",5). arg("Price",8));
• B. Move the line of code mentioned in option 1 into the last foreach statement in handleAction() of mymainwindow.cpp
• C. Replace the line of code mentioned in option 1 by the following code:
if (iList.size() >= 1) {
textEdit-> textCursor(). insertText(QString("%1\t%2\t%3\t%4\n"). arg("Barcode", 13).arg("Description", 20). arg("Stock",5).arg("Price",8));
}
• D. Replace the line of code mentioned in option 1 by the following code:
if (iList.toStringList().size() > 0) {
textEdit->textCursor().insertText(QString("%1\t%2\t%3\t%4\n").
arg("Barcode", 13).arg("Description", 20). arg("Stock",5). arg("Price",8));
}
In: Computer Science
WRITE A C++ PROGRAM:
QUESTION 1
In: Computer Science
Why is adherence to basic design principles important to the development of a website?
In: Computer Science
INRO TO DATABASES
Consider the following Schema:
Suppliers(sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)
The Catalog relation lists the prices charged for parts by Suppliers. Write the following queries in SQL using join, nested queries and set operators.
1. Find names of suppliers who supply every red or green part.
2. Find the sids of suppliers who supply every red part or supply every green part.
3. Find sids of suppliers who supply only red parts.
4. Find the pids of parts that are supplied by at least two different suppliers.
5. Find the sid of suppliers who charge more for some parts than the average price of that part.
In: Computer Science
Assignment
Write each of the following functions. The function header must be implemented exactly as specified. Write a main function that tests each of your functions.
Specifics
In the main function ask for a filename and fill a list with the values from the file. Each file should have one numeric value per line. This has been done numerous times in class. You can create the data file using a text editor or the example given in class – do not create this file in this program. Then call each of the required functions and then display the results returned from the functions. Remember that the functions themselves will not display any output, they will return values that can then be written to the screen.
If there are built in functions in Python that will accomplish the tasks lists below YOU CANNOT USE THEM. The purpose of this lab is to get practice working with lists, not to get practice searching for methods. DO NOT sort the list, that changes the order of the items. The order of the values in the list should be the same as the order of the values in the file.
Required Functions
def findMaxValue (theList) – Return the largest integer value found in the list.
def findMinValue (theList) – Return the smallest integer value found in the list.
def findFirstOccurance (theList, valueToFind) – Return the index of the first occurrence of valueToFind. If valueToFind does not exist in the list return -1.
def findLastOccurance (theList, valueToFind) – Return the index of the last occurrence of valueToFind. If valueToFind does not exist in the list return -1.
def calcAverage (theList) – Return the average of all the values found in the list.
def findNumberAboveAverage (theList) - Return the number of values greater than OR equal to the average. This requires you to call the calcAverage function from this function – DO NOT repeat the code for calculating the average.
def findNumberBelowAverage (theList) - Return the number of values less than the average. This requires you to call the calcAverage function from this function – DO NOT repeat the code for calculating the average.
def standardDeviation (theList) – Return the standard deviation of the values. To find the standard deviation start with the average of the list. Then for each value in the list subtract the average from that value and square the result. Find the average of the squared differences and then take the square root of that average.
For example, if the list contains the values 4, 5, 6, and 3 the average of those values would be 4.5. Subtract 4.5 from each value and square that results. The differences would be -0.5, 0.5, 1.5 and -1.5 respectively. The square of each of those differences would be 0.25, 0.25, 2.25, and 2.25 respectively. The average of these values is 1.25 ((0.25 + 0.25 + 2.25 + 2.25) / 4).
In: Computer Science
Assume you are talking with someone at work or home about the three components of credibility: competence, caring, and character. Express how you would describe these three components to someone using your own words.
In: Computer Science
Write a code in C that will take four words from the user and show those in ascending order.
In: Computer Science
IN PYTHON
Create a function called biochild.
The function has as parameters the number m and the lists
biomother and biofather.
The biomother and biofather lists contain 0’s and 1’s.
For example: biomother = [1,0,0,1,0,1] and biofather =
[1,1,1,0,0,1]
Both lists have the same length n.
The 0's and 1's represent bits of information (remember that a
bit is 0 or 1).
The function has to generate a new list (child).
The child list must have the same length n.
child is generated by randomly combining part of the child's
information
biomother and biofather.
The first part of the child list will be made up of the first b
bits of biomother
and the second part by the last n-b bits of the biofather.
For example, if b = 3, biomother = [1, 0, 0, 1,0,1] and biofather
= [1,1,1, 0, 0, 1],
then child = [1,0,0,0,0,1].
The value b has to be chosen randomly by the function.
After generating child, each bit in the list is considered for
mutation.
For each bit of child, with probability m the bit is “mutated” by
being replaced by its inverse
(If the bit is 0 it is replaced by 1, and if it is 1 it is replaced
by 0).
Finally, the function returns the list child.
In: Computer Science
2. Write a function that takes a tuple as an argument and returns the tuple sorted.
3. Write a statement that creates a dictionary containing the following key-value pairs:
'a' : 1
'b' : 2
'c' : 3
4. After the following code executes, what elements will be members of set3, ?
set1 = set([10, 20, 30, 40])
set2 = set([40, 50, 60])
set3 = set1.union(set2)
set4 = set1.intersection(set2)
set5= set1.difference(set2)
In: Computer Science
How would copyright affect your ability to "cheat" by looking up snippets of code on stack overflow
In: Computer Science
Lottery’s Powerball game, each ticket costs $2 and consists of two parts:--> Five distinct integers (i.e., no duplicates) between 1-69, inclusive • One integer (the “Powerball number”) between 1-26, inclusive. The Powerball number may or may not coincide with one of the previously chosen numbers. A ticket wins the jackpot if all five distinct numbers plus the Powerball number match the randomly drawn numbers. The matching of the five distinct numbers is done without regard to order. For example, a ticket with 54, 49, 3, 18, and 20 matches drawn numbers of 3, 54, 18, 20, and 49. In math, the set of five distinct numbers chosen by the player is known as a combination. The number of possible combinations of k items chosen from a set of n items is usually written as (pronounced “n choose k”) and is computable using this formula: This concept should be familiar; it was discussed in an earlier lab. As mentioned then, calculating the factorials directly is not an efficient way to find n choose k. This is because the terms in (n−k)! cancel some of the terms in n!, so there’s no need to compute those cancelled terms at all. A more efficient way to compute n choose k is this:
The number of possible Powerball tickets can be computed by letting n = 69, k = 5, and multiplying the result of n choose k by 26 (the quantity of possible Powerball numbers):Number of possible tickets = 26
plus one of m bonus numbers, we can compute the number of possible tickets like this. Number of possible tickets =
The game settings (i.e., the values of k, n, and m above) can be chosen by the play.All of your code should be within a single class named Lottery.java.numPossibleTickets(int k, int n, int m-->This method should return the number of possible tickets in a lottery game that involves choosing k distinct integers from 1 to n (inclusive), plus one bonus integer from 1 to m (inclusive). Use equation (3) to compute this, and use the efficient technique of equation (2) when computing the value of n choose k. Because the number of tickets can be quite large, return it as a long value.getPlayerNumbers(int k, int n-->This method should get user input for k distinct integers between 1 and n (inclusive). The results should be returned in a 1D array of length k. Include input validation with loops to ensure that each input cannot be outside the range 1 to n, and also does not duplicate any previously entered value.getDrawnNumbers(int k, int n-->This method should simulate randomly drawing k distinct integers between 1 and n (inclusive). The results should be returned in a 1D array of length k. countMatches(int[] a, int[] b-->This method should return the number of elements in array a that also appear in array b. You may assume that both parameter arrays contain distinct elements. Here are some example arguments for this method and their expected return values:
a |
b |
Return Value |
{1, 2, 3} |
{3, 1} |
2 |
{1, 2, 3} |
{5, 7, -1} |
0 |
1 2 3 4 || Bonus: 2
The moment of truth has arrived! Here are the drawn numbers:
4 2 1 3 || Bonus: 2
Your best ticket(s):
1 2 3 4 || Bonus: 2
You matched 4/4 drawn numbers.You did match the bonus number.WOOHOO, JACKPOT!!
Example program run (underlined parts indicate what the user enters)First, let’s set up the game!How many distinct numbers should the player pick? 5OK. Each of those 5 numbers should range from 1 to what? 69OK. And finally, the bonus number should range from 1 to what? -1Error - range must be at least 1 to 1 to have a valid game. Please try again: 26There are 292201338 possible tickets in this game. Each ticket has a3.4222978130237034E-7% chance of winning the jackpot. Let’s play, good luck!How many tickets would you like to buy? -22Error - must buy at least 1 ticket! Please try again: 3* Ticket #1 of 3 *Pick your 5 distinct numbers!Enter number 1 (must be 1-69, cannot repeat): 77Error - number must be between 1 and 69. Please try again.Enter number 1 (must be 1-69, cannot repeat): 1Enter number 2 (must be 1-69, cannot repeat): 2Enter number 3 (must be 1-69, cannot repeat): 3Enter number 4 (must be 1-69, cannot repeat): 4Enter number 5 (must be 1-69, cannot repeat): 5Now pick your bonus number (must be 1-26): 22Your tickets so far: --------------------
1 2 3 4 5 || Bonus: 22
* Ticket #2 of 3 *Pick your 5 distinct numbers!Enter number 1 (must be 1-69, cannot repeat): 55Enter number 2 (must be 1-69, cannot repeat): 22Enter number 3 (must be 1-69, cannot repeat): 33Enter number 4 (must be 1-69, cannot repeat): 44Enter number 5 (must be 1-69, cannot repeat): 22Error - you’ve already entered 22. Please try again.Enter number 5 (must be 1-69, cannot repeat): 11Now pick your bonus number (must be 1-26): 19
Your tickets so far: --------------------
1 2 3 4 5 || Bonus: 22
55 22 33 44 11 || Bonus: 19
* Ticket #3 of 3 *Pick your 5 distinct numbers!Enter number 1 (must be 1-69, cannot repeat): 8Enter number 2 (must be 1-69, cannot repeat): 13 Enter number 3 (must be 1-69, cannot repeat): 2Enter number 4 (must be 1-69, cannot repeat): 17Enter number 5 (must be 1-69, cannot repeat): 29Now pick your bonus number (must be 1-26): 4
Your tickets so far: --------------------
1 2 3 4 5 || Bonus: 22
55 22 33 44 11 || Bonus: 19 8 13 2 17 29 || Bonus: 4
*****
The moment of truth has arrived! Here are the drawn numbers:
43 3 22 36 51 || Bonus: 4
Your best ticket(s):
1 2 3 4 5 || Bonus: 22
55 22 33 44 11 || Bonus: 19
You matched 1/5 drawn numbers. You did not match the bonus number.
Sorry, no jackpot this time. Really, did you expect anything else?
Try may be next time!!!!
In: Computer Science
In python Complete the function get_Astring(filename) to read the file contents from filename (note that the test will use the file data.txt and data2.txt provided in the second and third tabs), strip off the newline character at the end of each line and return the contents as a single string.
In: Computer Science
When and how should resources be invested to close gaps between those who do and don’t use the Internet?
In: Computer Science