Category: Computer science and IT assignments

Handheld Solitaire

Handheld Solitaire
Handheld Solitaire requires no table, has simple rules, and is easily learned and played. It is played with a traditional 52 card deck of 4 suits (hearts, clubs, diamonds, and spades) and 13 ranks from ace (1) to king (13). Jokers are not included. The deck (face down) is held in one hand, while the actual hand of cards to be played is placed face up on top of the deck. This leaves the other hand free for dealing and discarding. The rules of play are as follows:
    Shuffle the deck, then hold it face-down in one hand.
    While the deck is not empty:
    Deal a single card from the top of the deck into the top of the playing hand
    While a match occurs in the playing hand between the top card and the card 3 back from it, either in rank or suit, collapse the hand using the following rules:
    If the ranks match, all 4 top cards of the hand are discarded. For example, if the cards are: 2S 6S 9C 2H , we would be comparing the last card dealt, 2S, to the card which is three back from it, 2H. Because the values match, we would discard all four cards.
    If the suits match, only the middle 2 (of the top 4) cards of the hand are discarded. For example, if the cards are: JH 3S 5C 7H , we would be comparing the last card dealt, JH, to the card which is three back from it, 7H. Because the suits match, we would discard the middle to cared (3S and 3C) and be left with JH 7H .
    The final score is the number of cards left in the hand at the end of the game.
There are several requirements in designing this project.
    A single card should be represented by a Card class. A card should be represented by a value (int) and a suit (char), and must include a pointer to a Card named nextCard as one of the private data members. Implement appropriate getter and setter functions and two constructors (one for default values and one with explicit parameters). It should also have a print() function described by the following bullet. Use Card.h and Card.cpp files to develop the class.
o    The print function should print the value and suit of the card in two characters. Thus, print the numerical value. However, if the value is 1, print A (for [A]ce); if it is 10, print T (for [T]en); if it is 11, print J (for [J]ack); if it is 12, print Q (for [Q]ueen); if it is 13, print K (for [K]ing). Follow this by the character representing the suit ([S]pades, [C]lubs, [H]earts, [D]iamonds), The following give some examples of a card, followed by how it should be printed:
    Ace of Hearts would be printed as: AH
    10 of Diamonds would be printed as: TD
    5 of Clubs would be printed as: 5C
    A deck and a playing hand of cards should each be represented by a CardLL class containing two private data members: a length variable to store the number of items in the CardLL object and a Card pointer named top. This will be a pointer to a linked list of Card objects (Cards will be the nodes of the linked list). Implement the class using CardLL.h and CardLL.cpp files. The functions to implement for this class are as follows.
o    CardLL (default constructor). The function sets the list pointer to be NULL and the length to be zero.
o    ~CardLL (destructor). Deletes each item from the list, one by one.
o    insertAtTop(suit, value). The function inserts a given card at the top of the list.
o    getCardAt(pos). This function will return a Card pointer which points to the card at the given position. If the position doesnt exist in the list, just return NULL.
o    removeCardAt(pos). This function will remove the card at the given position, returning true if successful. If the position outside the bounds of the list, return false.
o    getLength(). Returns the length of the list.
o    isEmpty(). Returns true if the list is empty; false otherwise.
o    print(). Prints the word top: followed by each card in the linked list, all on one line. (Utilize the Card print() function to aid with printing each individual card.
o    shuffle(). This will randomly shuffle a list of cards using the Fisher-Yates shuffle algorithm as follows (implement this function last):
    Use a while loop to walk through each Card in the list. Also within the loop:
    Get a random number between 0 and length 1
    Use getCardAt to get the card at that position
    Swap the card at the walk position with the card at the position random position. Just swap the suit and the value, not the nextCard pointer!
    Notes about random numbers:
    include the cstdlib and ctime files.
    place the following line as the first line of main(): 
    srand(time(NULL));
    In your CardLL classs shuffle() function, use rand() (with the modulus operator) to generate a random number in the appropriate range. Click here for an example of using rand()or consult page 274-275 of your textbook.
If there are additional class member functions that you would like to implement to ease the programming, you are allowed to do so. However, they should be clearly documented where necessary and should follow a structured object-oriented design approach.
Game play should be simulated in a client file called HHSolitaire.cpp. Follow the directions on the first page for the way the game is played. Represent the Deck and the Hand (playing hand) using a CardLL object for each. Use comments and functions to aid in the readability of your code. One function in particular to implement is populateDeck, which handles creating a new complete deck of 52 playing cards as follows (wrapped onto two lines below):
AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AS 2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS
Hint: To create the deck, use a nested for loop (one for the values [1-13] and one for the suits [D, C, H, S]) to generate the suits and values for the cards as you insert them into the deck.
    *Game play in this game, by its very nature, is deterministic. Thus, the entire game play can be printed to the output all at once. To give the program more of a game feel, though, you can use getchar() before each call to Hand.print() in main() to force the user to press the Enter key between each new card being played. Include stdio.h library in order to use this. This part should be saved until the very end of all testing!
Start early. I cannot emphasize this enough. This project will once again challenge your logical and critical thinking skills. Think of the design (structure, flow, logic sequence) of the program before implementing it. Learn from the previous projects. I will briefly reiterate the approach you should take below:
    Write down/draw out, on paper, how the overall design of the program should look. Getting your thoughts down on paper will help you organize/refine your approach and get a better grasp of how the individual components should fit together.
    Implement your program as empty function stubs at first and develop incrementally, testing one piece at a time before moving on. Building your program slowly from the ground up will allow you to foresee and prevent potential problems later on in development.
    Test many different input cases as you are developing your program and even once you feel that the program is complete. A good strategy is to try to break your program with a variety of different test casesit is much better for you to find a software mistake and fix it early than to have the final product fail the end user(s) because you didnt test adequately.
Testing: Test the program in steps. Build the Card and CardLL classes and verify that adding and deleting cards from the list works as you expect. Then start adding in individual elements of game play, incrementally. You will likely get segmentation faults as you develop this program. These are frustrating. However, these are a lot easier to debug if you test your program little by little.
Submission: This project is worth 110 points and is due on Friday, March 27th before noon. Submission must include:
    An electronic turn-in through Canvas. The entire Visual Studio solution folder must be zipped in order to do this. To create a zipped folder, right-click the folder and select Send to -> Compressed (zipped) folder. Rename this folder Project3_firstname_lastname where firstname and lastname are replaced with your first and last name, respectively. Upload this zipped folder to the Project 2 assignment page. Make sure that the following files are included in your project:
    HHSolitaire.cpp
    CardLL.cpp
    CardLL.h
    Card.cpp
    Card.h
    A paper printout of your code, along with console outputs from at least 3 separate program runs.
Grading: The program will be graded along the following dimensions. Note that the values in brackets are percentages of the project grade. Point distributions will be weighted accordingly.
    [20] Card implementation
    [35] CardLL implementation
    [35] HHSolitaire implementation
    [20] Overall quality of program design, code structure/readability, and user interaction
For the final bullet, ensure that the program files contain header comments, formatted as required by the CSCI documentation guidelines. Documentation (commenting) is used to illustrate major sections or unclear sections of code as well. Program design should clearly convey intent, especially focusing on proper use of variable names, whitespace, alignment and indentation

Make sure that the file names are correct, that your program contains no syntax errors, and that all of the code compiles. Programs that do not compile will receive an automatic 20 point deduction (20% of the project grade). This will be in addition to any deductions on the items listed above.

If you are unable to decipher a compiler error in your program, its better to comment out that section of code so that the program compiles without error. This way I can see that it was at least attempted and you may receive partial points for that section of code. In addition to the commented out section, write a detailed explanation of what you think the error may be, and the steps you tried in order to fix the error.

Academic Honesty: I expect you to maintain a high ethical standard when developing your programs. Students are bound by the academic honesty policies of the department, college, and university. Direct collaboration with others on this project is not permitted, and helping generate specific lines or chunks of code is strictly prohibited. General design strategies of the software program may be discussed at a high level.

Output: You may use the following as a guide to what your output should look like.

Top: 8C
Top: 9C 8C
Top: 4H 9C 8C
Top: 2S 4H 9C 8C
Top: TS 2S 4H 9C 8C
Top: 7H TS 2S 4H 9C 8C
Suit Match! Removing: TS 2S

Top: 7H 4H 9C 8C
Top: 7S 7H 4H 9C 8C
Top: KH 7S 7H 4H 9C 8C
Suit Match! Removing: 7S 7H

Top: KH 4H 9C 8C
Top: 9H KH 4H 9C 8C
Number Match! Removing: 9H KH 4H 9C

Top: 8C
Top: 8D 8C
Top: 3C 8D 8C
Top: QD 3C 8D 8C
Top: 4D QD 3C 8D 8C
Suit Match! Removing: QD 3C

Top: 4D 8D 8C
Top: 6C 4D 8D 8C
Suit Match! Removing: 4D 8D

Top: 6C 8C
Top: 2D 6C 8C
Top: AS 2D 6C 8C
Top: 9D AS 2D 6C 8C
Top: JS 9D AS 2D 6C 8C
Top: AD JS 9D AS 2D 6C 8C
Number Match! Removing: AD JS 9D AS

Top: 2D 6C 8C
Top: JC 2D 6C 8C
Suit Match! Removing: 2D 6C
Top: JC 8C
Top: AC JC 8C
Top: 4C AC JC 8C
Suit Match! Removing: AC JC

Top: 4C 8C
Top: TH 4C 8C
Top: 6H TH 4C 8C
Top: 5D 6H TH 4C 8C
Top: JH 5D 6H TH 4C 8C
Suit Match! Removing: 5D 6H

Top: JH TH 4C 8C
Top: 7C JH TH 4C 8C
Suit Match! Removing: JH TH

Top: 7C 4C 8C
Top: 4S 7C 4C 8C
Top: AH 4S 7C 4C 8C
Top: KC AH 4S 7C 4C 8C
Suit Match! Removing: AH 4S

Top: KC 7C 4C 8C
Suit Match! Removing: 7C 4C

Top: KC 8C
Top: 5H KC 8C
Top: 2H 5H KC 8C
Top: QC 2H 5H KC 8C
Suit Match! Removing: 2H 5H

Top: QC KC 8C
Top: TD QC KC 8C
Top: 3S TD QC KC 8C
Top: 5C 3S TD QC KC 8C
Suit Match! Removing: 3S TD

Top: 5C QC KC 8C
Suit Match! Removing: QC KC

Top: 5C 8C
Top: 8H 5C 8C
Top: KS 8H 5C 8C
Top: 2C KS 8H 5C 8C
Suit Match! Removing: KS 8H

Top: 2C 5C 8C
Top: 6D 2C 5C 8C
Top: 3H 6D 2C 5C 8C
Top: KD 3H 6D 2C 5C 8C
Top: 3D KD 3H 6D 2C 5C 8C
Suit Match! Removing: KD 3H

Top: 3D 6D 2C 5C 8C
Top: 7D 3D 6D 2C 5C 8C
Top: JD 7D 3D 6D 2C 5C 8C
Suit Match! Removing: 7D 3D

Top: JD 6D 2C 5C 8C
Top: TC JD 6D 2C 5C 8C
Suit Match! Removing: JD 6D

Top: TC 2C 5C 8C
Suit Match! Removing: 2C 5C

Top: TC 8C
Top: 5S TC 8C
Top: QH 5S TC 8C
Top: 8S QH 5S TC 8C
Top: 9S 8S QH 5S TC 8C
Suit Match! Removing: 8S QH

Top: 9S 5S TC 8C
Top: QS 9S 5S TC 8C
Top: 6S QS 9S 5S TC 8C
Suit Match! Removing: QS 9S

Top: 6S 5S TC 8C

Deck Empty! Printing leftover hand:

Top: 6S 5S TC 8C

Hurricane Data OOP Program

All I need done is a code written converting the already written hurricane data java code (included below) into OOP format. It’s not too difficult, its for my APCS A highschool course, I just don’t have time to write it. I have attached the instructions and rubric as well.

Simple Visual Basic Program for class

Write a Class that will (as an object) take in at least two types of information, such as name and phone number. In the Class, process the data and output the information as a Form. As part of your code, instantiate the Class at least twice in other words, create two different objects from your Class. You can be creative.

Python assignment

please see attached document for instructions

COMP 2152 Assignment Winter 2020
Important:
1.    This is an individual assignment (complete the requirements on your own).
2.    Do not share the assignment requirements with any former or future students in COMP 2152. Do not share this assignment requirements online in any format, anywhere.
3.    You may choose to complete the all requirements or attempt to complete as much as possible.
4.    Credit will be awarded for requirements completed correctly and entirely with the portion of program functioning as requested. No partial marks will be awarded.
5.    You are allowed to make assumptions about application functionality not mentioned in the project idea (which is more of a general guideline).
6.    At minimum your project must display the functionality described for the idea selected. Any functionality described that is not a part of your submission will result in grade penalties at the discretion of the instructor.
Submission:
–    Submit Python files only. No other format is accepted.
–    DO NOT submit zipped (compressed) files. Any compressed files will not be marked.
–    Submit in  GB Learn and Blackboard!!
Select one of the project ideas below and develop a Python application that meets the requirements described below:
Project ideas (should you want to work on another idea make sure to check with your instructor first):
7.    Online store: users should be able to order items for sale or combo items (items when bought together trigger a discount). The order should include number of items and prices for items and should generate and display receipts.
8.    MP3 Player: the user should be able to choose music categories, individual songs, or artists and should be able to buy an album, or a song. The user should be buying one or more selection, including mixed selections. The user should be able to listen to a 10 seconds sample song selection of their choice.
9.    File manager: the user should be able to create folders and subfolders and should be able to copy and move files to the newly created directories. The user should be able to sort the directories. The user should be able to see what files are in a directory of choice.
10.    Library: users should be able to search for books by title or by author, should be able to search by book category (fiction, non-fiction, autobiographies, travel, etc.). The user should be able to purchase one or more books in any combination of authors, titles, categories, etc. The application should generate and display a receipt stating the list of books selected and their return due dates.
11.    Expense tracker: the user should be able to enter expenses per category (food, clothing, entertainment, rent, etc) and the application should track the expenses per week or month. The user should be able to see their total expenses for a month of their choice for each category and a total monthly expense. The monthly expense report should include average expenses for each category for the year and indicate if the user expense for the month selected is lower or higher than the annual average. Also, the report should display the percentage of expenses from each category out of the total monthly expenses.

Project application requirements:

Requirements description    Points
Basic:
1.    Project should have a functioning menu
2.    Project should have adequate functions (minimum 3 functions)
3.    Project should make use of files to save the data
4.    Project should handle adequate exceptions
5.    Project should display information formatted adequately
6.    Project should make use of lists or dictionaries as appropriate.
7.    Project should follow adequate naming conventions for variables and functions, and should have comments as appropriate.    
10
10
10
10
10
10
10
Intermediate:
8.    Project should use an object-oriented approach
9.    Project should use a database   
10
10
Advanced:
10.    Project should use a GUI platform   
10
   
Total    100

Hurricanes Data Challenge Program

All I need done is a code written converting an already written java code into OOP format. It’s not too difficult, its for my APCS A highschool course, I just don’t have time to write it. Email me back for all the information and programs needed to complete this!

Dictionaries

You should create a program that manages a tab-separated text file containing employees travel expenses. There are 4 and only 4 employees who travel for the company: alice, bob, carl, and diane. Each record in the data file will contain an employee name, a destination city, miles traveled, and gallons used.

In the data file itself, each field in a record is separated by a tab character (“t”). Here are the records to be used in the file; it may not look like it, but each field is tab-separated. If you copy and paste this data into your data file, you may or may not need to edit it a bit in Notepad (or similar) to make sure there is only 1 tab between each of the 4 fields. There is no tab between st. and louis, only a space. When this data is read into your program it will be converted into a list of dictionaries, where each row in the data is a dictionary with 4 keys: name, city, miles, and gallons.

alice    chicago    663    20.7
bob    indianapolis    226    8.7
alice    nashville    409    16.4
carl    indianapolis    243    8.4
diane    st. louis    581    16.4
bob    st. louis    560    18.1
bob    cincinnati    237    6.6
alice    chicago    681    17.9
alice    nashville    422    14.6
diane    chicago    676    22.5
carl    indianapolis    243    6.4
diane    indianapolis    276    7.7
diane    indianapolis    241    9.4
You will likely find it easier to use the data file as given in this link: travels.txt

You will find the base code for this program given near the bottom of the page in the lecture notes that discuss dictionaries, along with a video explaining how it works. That code will already contain functions for creating a menu, reading the data from a file, adding a record, and a function to store the data back to the text tile–all using the data given above! That discussion will certainly help you get a good start on this assignment. A picture of the menu you need to use is given below. Note option 2, which is new.

menu

Here’s what it might look like if you select option 1 to display all the data, with the data formatted to line up in neat columns. As mentioned above, code for this much of the program (with the exception of option 2) can be copied from the lecture notes.

everyone’s data

So, what is it that you need to do? You need to add the functionality so that clicking option 2 will display the total miles and gallons used by one of the employees. When option 2 is exercised you should enter one of the 4 employee’s first names, then the following should be displayed: that person’s name and total miles traveled, for all cities, total gallons used, average miles per gallon overall, and the expense value for the total miles at 75 cents per mile. Like this, for alice.

We exercise option 2, then enter alice’s name, then we see that alice has racked up a total of 2175 miles, used a total of 69.6 gallons for an average miles-per-gallon value of 31.3 mpg. And, alice should get an expense check for 2175 * .75 = $ 1631.25. If using option 2 you entered the name bob, you’d see bob’s calculated data (1023 total mile with the given data, etc.).

alice’s data

So, basically, you need to add 1 function to the base code given in the notes. For option 2, you will essentially need to read each record with a loop and accumulate totals for miles and gallons, but only if the entered user name matches a name in a record (think if-statement). If you’ve forgotten what an accumulator is, go back to the material where the for-loop was introduce.

So, enter a name, set up a for-loop that loops thru the data, if the entered name matched the name in the record, add the miles to a variable, the gallons to a variable, with the loop keeping a running total.

After the loop runs, mpg is total miles divided by total gallons, and the expense check is just total miles times .75.

For full credit:

Your program should properly read and store the given data to and from the tab-separated data file. That is, I should be able to use your program with my data file without error.
When the data is read into your program it should be organized as a list of dictionaries, where each dictionary is a row in the file, using these dictionary keys: name, city, miles, gallons.
You need to add functionality to display the user’s name, total miles traveled, total gallons used, average mpg, and the expense of the total miles at 75 cents per mile. This should work for any of the 4 proper user names you enter.

3 labs for computer science

Lab 1:

Using the GroceryItem struct from Assignment 5 create a source.cpp file and a main function. Put the GroceryItem struct above int main. We are going to create a grocery store full of items!

Create two copies of this source.cpp file.

Array Version
In the first copy we are going to use a three dimensional array. The three dimensions have size 6, 3, and 5. These represent the aisle, section in the aisle, and the shelf number of the grocery item. Using no loop or selection constructs. Ask the user for the price and location for two grocery items.

Create an instance of the GroceryItem for each, but do not fill out the Location struct. Instead, insert the item in the proper location in the array.

Vector Version
Do the same as in the array version, but instead, make a single dimensional vector of GroceryItems and fill out the Location member in the struct. Simply push_back each grocery item onto the vector.

Lab 2:

We are going to be updating the vector version of assignment 7.

Use a while loop to ask the user if they want to add another item to vector<GroceryItem> store;
If they do:
push an empty GroceryItem struct onto the vector
fill out the struct by using store.back() and asking the user for:
type
price
quantity
name
location
Else exit the loop
use a ranged based for loop to loop over the vector and neatly print out all the information for every GroceryItem in the store vector.

Lab 3:

Write a function called Inventory, that takes a vector of GroceryItems (you decide whether it should be pass-by-reference or pass-by-value). The function should add up the quantity of all the items in the vector and return the sum of all items in the store.

Assignment

Write a program with a graphical interface that allows the user to convert an amount of money between U.S. dollars (USD), euros (EUR), and British pounds (GBP). The user interface should have the following elements: a text box to enter the amount to be converted, two combo boxes to allow the user to select the currencies, a button to make the conversion, and a label to show the result. Display a warning if the user does not choose different currencies. Use the following conversion rates: 1 EUR is equal to 1.42 USD. 1 GBP is equal to 1.64 USD. 1 GBP is equal to 1.13 EUR. It is the programmers responsibility to ensure that no matter what the user enters, the program does not crash. Call the main program Converter.java. You will need another class for the frame.
Follow all directions in the COP3337 Class Rules for Submitting Programs. Please remove any package statements in your program. The program must compile and run from the command line no matter what IDE you use. Note that a program that does not compile and run and do some part of the assignment will not earn any points.

Palindrome Tester (Using Java Queue)

Purpose

The purpose of this project is to practice with using and implementing Queues.

Objective

You are to implement a program to test to see if the entered word is a palindrome. A palindrome in this case is a word that reads the same backward as it does forward. Your program should take in a word from the user and store the word character by character onto a queue. Queues use the FIFO (First in first out) method to access and add data elements. You should use the java.util.Queue to implement the built in queue for this project. Once all the characters are in the queue you should then remove the characters one by one from the queue and store them in a string. Next you should print out the reverse of the word that is entered. Then print out whether or not the word that was entered by the user was a palindrome or not. Your program should loop until the word exit is typed in.

Instructions

1. Implement the java.util.Queue that is built into Java.
2. Take in a word from the user.
3. Print out the word in reverse.
4. Check to see if the word is a palindrome.
5. Print out whether or not the word is a palindrome.
6. Loop continuously until the word exit is typed in. At which time the program should exit.
7. Your output should look similar to my sample output below.
8. Zip up the files and submit them on Brightspace under the correct assignment.

Sample Output:

Enter any word to see if it is a Palindrome:
civic
The word in reverse is: civic
The word is a palindrome.
Enter any word to see if it is a Palindrome:
potato
The word in reverse is: otatop
The word is not a palindrome.
Enter any word to see if it is a Palindrome:
kayak
The word in reverse is: kayak
The word is a palindrome.
Enter any word to see if it is a Palindrome:
racecar
The word in reverse is: racecar
The word is a palindrome.
Enter any word to see if it is a Palindrome:
aaron
The word in reverse is: noraa
The word is not a palindrome.
Enter any word to see if it is a Palindrome:
exit
Exiting …

Java Program Using Circular Array Queues

Using circular array queues, you must design a program that calculates the shortest possible path from the starting point to end point. Full assignment details can be found in the attached PDF. Use the given test file to check that the program is running to the proper specifications. Once all test cases pass, then it should be good to go.