CS204 – (Solution)

$ 29.99
Category:

Description

Faculty of Engineering and Natural Sciences
CS204 Advanced Programming

Homework 2 – Alan’s Psychedelic Breakfast

DISCLAIMER:
Your program should be a robust one such that you have to consider all relevant user mistakes and extreme cases; you are expected to take actions accordingly!

Only checking the sample run cases might not be sufficient as your solution will be checked against a variety of samples different than the provided samples; however checking these cases are highly encouraged and recommended.

Introduction
The aim of this homework is to practice on linked lists structures. In this homework, you will implement a dynamic shopping list for Alan’s psychedelic breakfast by using a circular doubly linked list. Several operations will be available to the user through a recurring menu.

Input to Your Program
All inputs to your program will be done through a option menu which looks like below:

user.

Format of the Inputs

For the options “1” and “2”, the name of the item will be asked. This item name might consist of multiple words and there can be multiple spaces or tabs between the words. Your program should handle these cases and the final item name should have single spaces between the words (and no space in the end 🙂 ). A good way to handle this might be reading the console input by getline and split this line into words by using a string stream. You can use getline for reading standard input like this:

string line; cin.ignore(); getline(cin, line);

And the string line will hold the whole line of the input from the console.

Moreover, Alan is a little obsessed and likes everything written in uppercase. So, all letters of the item names should be capitalized, you can use the strutils library for this purpose. The cpp and header of the abovementioned library are given to you with the homework bundle. Besides, as mentioned above, for each item, there will be quantity and estimated-price-per-quantity data. These two fields should be considered as integers. You are free to assume that the user enters a positive integer for those fields all the time.

For more information regarding this situation, you can check this page:
http://wiki.c2.com/?RealNumbersAreNotEqua l

Data Structure to be Used
You must use a circular doubly linked list for the implementation of the shopping list. Apart from the automated grading, we will also inspect your code in detail. Faking to use a linked list will not help you and you will end up with a grade of 0 directly. So, please do not try to get away with a vector or array implementation.
You can encapsulate the name, quantity and estimated price information regarding one item in a struct, as we did for all the linked list examples in this course. Then, you can basically form a circular doubly linked list of these struct elements. Remember that you should also have some kind of pointers in these structs for connecting them to each other. You are also allowed to keep extra fields in the struct if you feel like so, but these three data fields (and some pointers ) should be enough minimally.

Details of the Tasks and Outputs of Your Program

For the first two tasks, there are two points to be clarified. First of all, after getting the names of the items, you should consider their uppercase versions, otherwise you might have duplicate entries in your list or your deletion operations might fail unexpectedly. Always try to convert names to uppercase as soon as you obtain them. Second thing is that Alan is a little keen on his shopping list and he wants things organized according to some measures. For this, you should always have the list sorted with respect to the total estimated prices (i.e., quantity * e.price) of the items. If two items have equal estimated prices, they should be sorted with respect to their names alphabetically (greater total estimated price comes first; if equal, smaller name comes
first).

The third and fourth tasks are basic linked lists traversals. In order for your program to find the correct results in these steps, your list should be sorted (descending wrt estimated price and ascending wrt name if necessary) after each action taken in first and second tasks. For the format which you will show items in the console, you can see the sample runs below.

The fifth task is another linked linked list traversal problem, so it does not need much explanation, we assume.

Sample Runs
Below, we provide some sample runs of the program that you will develop. The italic and bold phrases are the standard inputs (cin) taken from the user (i.e., like this ). You have to display the required information in the same order and with the same words as here.

Sample Run 1
This program helps Alan with gathering the shopping list for his psychedelic breakfast.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 0

This is not a valid option!

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 7

This is not a valid option!

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list 6. Exit

Enter your choice: Alan

This is not a valid option!

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 3

The shopping list is empty.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 4

The shopping list is empty.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 5

The total estimated price of 0 kinds of items is: 0

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 6

Clearing the shopping list…
Exiting the program…

Sample Run 2
This program helps Alan with gathering the shopping list for his psychedelic breakfast.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: bread
Enter quantity for the item: 2
Enter estimated price for the item: 1

The item BREAD of quantity 2 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: CoffEE
Enter quantity for the item: 3
Enter estimated price for the item: 2

The item COFFEE of quantity 3 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 3

Item: COFFEE
Quantity: 3
Est. Price: 2

Item: BREAD
Quantity: 2
Est. Price: 1

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: sausages
Enter quantity for the item: 2
Enter estimated price for the item: 21

The item SAUSAGES of quantity 2 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 5

The total estimated price of 3 kinds of items is: 50

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: BreAD
Enter quantity for the item: 4

The quantity of the item BREAD is increased by 4. The final quantity is 6.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 4

Item: COFFEE
Quantity: 3
Est. Price: 2

Item: BREAD
Quantity: 6
Est. Price: 1

Item: SAUSAGES
Quantity: 2
Est. Price: 21

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: marmalade
Enter quantity for the item: 2
Enter estimated price for the item: 5

The item MARMALADE of quantity 2 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 3

Item: SAUSAGES
Quantity: 2
Est. Price: 21

Item: MARMALADE
Quantity: 2
Est. Price: 5

Item: BREAD
Quantity: 6
Est. Price: 1

Item: COFFEE
Quantity: 3
Est. Price: 2

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 2

Enter an item name to delete from the list: BRead

The item BREAD is deleted from the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 3

Item: SAUSAGES
Quantity: 2
Est. Price: 21

Item: MARMALADE
Quantity: 2
Est. Price: 5

Item: COFFEE
Quantity: 3
Est. Price: 2

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 5

The total estimated price of 3 kinds of items is: 58

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 2

Enter an item name to delete from the list: coffee

The item COFFEE is deleted from the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 2

Enter an item name to delete from the list: coffee The item COFFEE could not be found in the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 4

Item: MARMALADE
Quantity: 2
Est. Price: 5

Item: SAUSAGES
Quantity: 2
Est. Price: 21

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 2

Enter an item name to delete from the list: sauSAGES

The item SAUSAGES is deleted from the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 5

The total estimated price of 1 kinds of items is: 10

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 3

Item: MARMALADE
Quantity: 2
Est. Price: 5

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 2

Enter an item name to delete from the list: marmalaDE

The item MARMALADE is deleted from the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit
Enter your choice: 3

The shopping list is empty.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 2

Enter an item name to delete from the list: peace

The item PEACE could not be found in the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: bACon
Enter quantity for the item: 100
Enter estimated price for the item: 4

The item BACON of quantity 100 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: peace
Enter quantity for the item: 1
Enter estimated price for the item: 100000

The item PEACE of quantity 1 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 4

Item: BACON
Quantity: 100
Est. Price: 4

Item: PEACE
Quantity: 1
Est. Price: 100000

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 5

The total estimated price of 2 kinds of items is: 100400

MENU

1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 1

Enter name for the item: GooD daY
Enter quantity for the item: 1
Enter estimated price for the item: 5000

The item GOOD DAY of quantity 1 is added to the list.

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 3

Item: PEACE
Quantity: 1
Est. Price: 100000

Item: GOOD DAY
Quantity: 1
Est. Price: 5000

Item: BACON
Quantity: 100
Est. Price: 4

MENU
1. Add item to the shopping list
2. Delete item from the shopping list
3. Print the shopping list
4. Print the shopping list in reverse order
5. Show total estimated cost of the list
6. Exit

Enter your choice: 6

Clearing the shopping list…
Exiting the program…

Some Important Rules

How to get help?

YOU CAN USE GRADE CHECKER FOR THIS HOMEWORK!
You can use GradeChecker (http://sky.sabanciuniv.edu:8080/GradeChecker /) to check your expected grade. Just a reminder, you will see a character ¶ which refers to a newline in your expected output.

Make sure you upload the strutils.h and strutils.cpp files, too.

Common Errors Page: http://sky.sabanciuniv.edu:8080/GradeChecker/commonerrors.js p

Submit via SUCourse ONLY! Grade Checker is not considered as a submission. Paper, e-mail or any other methods are not acceptable, neither.

The internal clock of SUCourse might be a couple of minutes skewed, so make sure you do not leave the submission to the last minute. In the case of failing to submit your homework on time:
“No successful submission on SUCourse on time = A grade of 0 directly.”

What and where to submit (PLEASE READ, IMPORTANT)
You should prepare (or at least test) your program using MS Visual Studio 2012 C++. We will use the standard C++ compiler and libraries of the abovementioned platform while testing your homework.

It’d be a good idea to write your name and lastname in the program (as a comment line of course). Do not use any Turkish characters anywhere in your code (not even in comment parts). If your full name is “Duygu Karaoğlan Altop”, and if you want to write it as comment; then you must type it as follows:

// Duygu Karaoglan Altop

Submission guidelines are below. Since the grading process will be automatic, you are expected to strictly follow these guidelines. If you do not follow these guidelines, your grade will be zero. The lack of even one space character in the output will result in your grade being zero, so please test your programs yourself and with the Grade Checker tool explained above.

● Name your cpp file that contains your program as follows:

“SUCourseUserName_hw2.cpp”

Your SUCourse user name is actually your SUNet username which is used for checking sabanciuniv e-mails. Do NOT use any spaces, non-ASCII and Turkish characters in the file name. For example, if your SU e-mail address is atam@sabanciuniv.edu , then the file name must be: “atam_hw2.cpp”

● Please make sure that this file is the latest version of your homework program.

● You should upload strutils.h and strutils.cpp to SUCourse as well.

● Do not zip any of the documents but upload them as separate files only.

● Submit your work through SUCourse only! You can use the Grade Checker only to see if your program can produce the correct outputs both in the correct order and in the correct format. It will not be considered as the official submission. You must submit your work to SUCourse.

Good Luck!
Tolga Atam, Duygu K. Altop

Reviews

There are no reviews yet.

Be the first to review “CS204 – (Solution)”

Your email address will not be published. Required fields are marked *