Questions
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp -...

(1) Create three files to submit:

  • ItemToPurchase.h - Class declaration
  • ItemToPurchase.cpp - Class definition
  • main.cpp - main() function

Build the ItemToPurchase class with the following specifications:

  • Default constructor
  • Public class functions (mutators & accessors)
    • SetName() & GetName() (2 pts)
    • SetPrice() & GetPrice() (2 pts)
    • SetQuantity() & GetQuantity() (2 pts)
  • Private data members
    • string itemName - Initialized in default constructor to "none"
    • int itemPrice - Initialized in default constructor to 0
    • int itemQuantity - Initialized in default constructor to 0

(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.

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...

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 ?

  1. It is a QMap and thus an ItemList object is a QMap itself
  2. It has a QMap, which cannot be accessed outside this class
  3. ItemList uses a heap QMap object
  4. QMap used by ItemList uses Item pointers as keys

Question 2

Which of the following is true about the menu option, Open?

  1. It is only available before the user has entered items manually using Add/A icon
  2. It is only available after the user has entered items manually using Add/A icon
  3. It is available before and after the user has entered items manually
  4. It is no longer available after the user has saved the data in a file

Question 3

What is meant by separating model and view?

  1. Model handles data and view handles how the model is displayed on the screen
  2. View handles data and model may handle how the data is displayed on the screen
  3. Both model and data can handle data/model/logic of the application
  4. Both model and data can handle the data representation on the screen

Question 4

In the given project, how do the view classes access the data in the model classes?

  1. Via inheritance between view and model classes
  2. Via signals and slots
  3. View objects invoke functions on model objects
  4. Model classes are composed of view classes

Question 5

Which of the following is a view class in the given project?

  1. Item
  2. itemList
  3. ItemReader
  4. ItemDialog

Question 6

Why is QActionGroup used in this project?

  1. It is not possible to achieve the desired GUI functionality without QActionGroup
  2. Without it, we need 18 QAction objects
  3. It is necessary to display images on the GUI
  4. It allows grouping of QAction, which can be used to provide same actions in different controls of the GUI

Question 7

Which of the following is a model class in the given project?

  1. MyMainWindow
  2. ItemList
  3. ItemMap
  4. ItemDialog

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?

  1. Each image appears once on the window
  2. Each image appears twice on two different control options on the window
  3. Each image appears thrice on three different control options on the window
  4. Each image appears in four on different control options on the window

Question 9

Which is the correct description of line 83 (*i=*j) in mymainwindow.cpp?

  1. I and j point to the same item object
  2. I and j point to the same heap memory location that has two different item objects
  3. I and j point to two different Item objects with different states
  4. I and j point to two different item objects with the same state

Question 10

Which of the following is incorrect about ItemDialog?

  1. It creates an instance of itself when adding and editing itself
  2. It creates an Item object when the user requests to add an item
  3. It creates an Item object when the user requests to change an item
  4. When the user requests to change, it uses a QInputDialog to get the bar code of the item that the user wants to change

Question 11

Which of the following is incorrect about the project?

  1. It manages a collection of Item objects
  2. It allows the user to read Items from a previous execution of the project
  3. It allows the user to save Items in a comma-separated format
  4. It allows the user to exit the program without saving data

Question 12

What does the icon R stand for?

  1. Read
  2. Retry
  3. Remove
  4. Revise

Question 13

When the user initiates the Save option, which of the following is correct?

  1. It results in a function being executed on an ItemList object, which in turn uses an object of ItemWriter to save
  2. It results in a function being executed on an ItemList object, which in turn uses an object of ItemReader to save
  3. It results in the direct execution of a function on an ItemWriter object
  4. It results in the direct execution of a function on an ItemReader object

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?

  1. It ignores the users request
  2. It ignores the user request but warns the user
  3. It gives the user the option to change the bar code
  4. It allows the user to change the number of items in stock of the existing item

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?

  1. Copy all six images to the project folder
  2. Copy the icons folder to the build project folder
  3. Copy all six images to the project build folder
  4. Add the icons folder to the project as other files

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 Assume you have a hobby to collect a particular type...

WRITE A C++ PROGRAM:

QUESTION 1

  1. Assume you have a hobby to collect a particular type of items. Specify the category to which the items you collect belong to ____________________________
    1. [2 points] Define a struct with the name the same as the category that you filled in the blank above
    2. [4 points] The struct must have at least two members corresponding to properties relevant to the items in the category you specified. The struct members must have names meaningful to the items.
    3. [2 points] Declare an array to store 100 of your hobby items.
    4. [2 points] Declare another array to store 100 of the hobby items that belong to a friend
    5. [2 points] Declare a two dimensional array called matchingPairs that has a maximum of 100 rows. The values in this array will be indices to arrays declared in c and d.
    6. [5 points] Write a function to read values into any array similar to the ones in c and d. Note that when the function returns, the array that is passed into the function must contain the values read in.
    7. [5 points] Write statements to call the function in f to read values into arrays declared in c and d.
    8. [5 points] Write a function that takes in two arrays similar to the ones in c and d and returns an array similar to the one in e. The function must compare elements in the input arrays and store indices where matches are found. For instance, if the item in array index 5 of the first array matches the item in array index 2 of the second array, then 5 and 2 are stored in one row in the third array. Care must be taken to ensure that the first two arrays remain intact, that is no changes happen in the first two arrays.
    9. [5 points] Write code to call the function in h and print the results of the array returned by the function in h.
    10. Adequate comments in code [3 points]
    11. Program structure and readability [5 points]

In: Computer Science

Why is adherence to basic design principles important to the development of a website?

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:...

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....

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:...

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...

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...

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

Given the list values = [], write code that fills the list with each set of...

  1. Given the list values = [], write code that fills the list with each set of numbers below. Note: use loops if it is necessary
  1. 1 2 3 4 5 6 7 8 9 10
  2. 0 2 4 6 8 10 12 14 16 18 20
  3. 1 4 9 16 25 36 49 64 81 100
  4. 0 0 0 0 0 0 0 0 0 0
  5. 1 4 9 16 9 7 4 9 11
  6. 0 1 0 1 0 1 0 1 0 1
  7. 0 1 2 3 4 0 1 2 3 4

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...

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.,...

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 (nk)! 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. The main method should tie everything together. Call your previously written methods as necessary. Here’s a summary of what the main method should do:Get user input for how to set up the lottery game (i.e., get values for k, n, and m). Include input validation with loops to ensure that k ≥ 1, nk, and m ≥ 1.Show how many possible tickets exist for that game, and a single ticket’s chance of winning the jackpot.Get user input for t, how many tickets to buy. Include input validation with a loop to ensure that t ≥ 1.For each ticket, get user input for the k distinct numbers to play and the corresponding bonus number. Include input validation with loops to ensure that all the numbers are valid. (The distinct numbers should already be validated from the method getPlayerNumbers.)Once all tickets have been entered, simulate the lottery drawing.Find and show the “best” ticket(s). The “best” ticket is the one that matches more of the k distinct numbers than any other ticket. Matching the bonus number is used as a tiebreaker. For example, in a game that involves selecting 3 distinct numbers, here’s a hierarchy of possible tickets from best to worst:
    • All 3 numbers match, plus the bonus number (this wins the jackpot)
    • All 3 numbers match, without the bonus number
    • 2 of 3 numbers match, plus the bonus number
    • 2 of 3 numbers match, without the bonus number
    • 1 of 3 numbers match, plus the bonus number
    • 1 of 3 numbers match, without the bonus number
    • 0 of 3 numbers match, and the bonus number matches
    • 0 of 3 numbers match, and the bonus number doesn’t match In case two or more tickets tie for “best,” show all of them.
  • For the best ticket(s), show how many of the k distinct numbers match the drawn numbers, whether the bonus number matches, and whether the jackpot was won. To win the jackpot, all k distinct numbers and the bonus number must match the drawn numbers.The next pages have examples of how your completed program might look when running.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? 4 OK. Each of those 4 numbers should range from 1 to what? 3Error - range must be at least 1 to 4 to have a valid game. Please try again: 4OK. And finally, the bonus number should range from 1 to what? 2-->There are 2 possible tickets in this game. Each ticket has a 50.0% chance of winning the jackpot. Let’s play, good luck!How many tickets would you like to buy? Error - must buy at least 1 ticket! Please try again: 1* Ticket #1 of 1 *Pick your 4 distinct numbers!Enter number 1 (must be 1-4, cannot repeat): 1Enter number 2 (must be 1-4, cannot repeat): 2 Enter number 3 (must be 1-4, cannot repeat): 1Error - you’ve already entered 1. Please try again.Enter number 3 (must be 1-4, cannot repeat): 3Enter number 4 (must be 1-4, cannot repeat): 1Error - you’ve already entered 1. Please try again.Enter number 4 (must be 1-4, cannot repeat):4Now pick your bonus number (must be 1-2): 3Error - number must be between 1 and 2. Please try again: 2Your tickets so far: --------------------

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...

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...

When and how should resources be invested to close gaps between those who do and don’t use the Internet?

In: Computer Science