Using C++. Implement l_list.cpp and l_list.h
l_list and encounterNode. The former is a richly featured linked list with a wide variety of methods and the latter is a node meant to encapsulate a game encounter. In the context of this task, the encounterNode represents a battle encounter. Each encounter will describe what a player has to watch in the course of the level in terms of enemies, rewards and such. Therefore a combination of encounterNodes contained within a linked list would represent a single level in a game. The classes and behaviors of their methods are detailed below:
l_list
-head: encounterNode*
---------------------------
+l_list()
+~l_list()
+addToFront(a:string*, b:int, c:string):int
+addToBack(a:string*, b:int, c:string):int
+addAtIndex(a:string*, b:int, c:string, index:int):int
+getListSize():int
+removeFromFront():encounterNode*
+removeFromBack():encounterNode*
+removeFromIndex(index:int):encounterNode*
+printSummaryOfList():void
+printList():void
The class has the following variables:
•head: The head pointer which demarcates the start
of the list.
The class has the following methods:
•l_list: The list constructor. It will start by
initialising a blank list with no elements.
•∼l_list: The list destructor. It should delete all of the remaining nodes in the list and deallocate all of the memory contained within. After deleting the list, it should print out the following message: ”Number of nodes deleted: X” without quotation marks where X indicates the number of nodes deleted in the process. Be sure to add a newline at the end of this output.
•addToFront: This method receives the variables to construct a new node and then allocates memory for it before adding it to the list at the front. It returns the new size of the list, that is the size of the list with the added node.
•addToBack: This method receives the variables to construct a new node and then allocates memory for it before adding it to the list at the back of the list. It returns the new size of the list, that is the size of the list with the added node.
•addAtIndex: This method receives the variables required to instantiate a new node as well as an index. This method should insert this node into the list at the given index. If the given index is not contained within the list, such as inserting at 5 when the list is only 2 nodes big, instead you must add it to the front. Note that the list is 0-indexed. It returns the new size of the list, that is the size of the list with the added node.
•getListSize: This method determines the number of nodes in the list and returns this as an integer.
•removeFromFront: This remove method removes a node from the list from the front and returns it. Note that the node is returned and not deleted; it must be properly unlinked from the list without being destroyed. If the list is empty, return NULL.
•removeFromBack: This remove method removes a node from the list from the back and returns it. Note that the node is returned and not deleted; it must be properly unlinked from the list without being destroyed. If the list is empty, return NULL.
•removeFromIndex: This method receives an index of a node to remove from the list. This node must be removed and returned without being destroyed; that is, unlinked from the list without being deleted. Note that if the index is not valid or the list is empty then the method should return NULL. The list is 0-indexed.
•printList: This method prints out the entire
list, starting from the front. If the list is empty, print ”EMPTY
LIST” without the quotation marks and a newline at the end. The
example output is given below:
Node 0
Number of Enemies: 2
Reward: Boots of Healing
Enemy 1: Imp
Enemy 2: Imp
Node 1
Number of Enemies: 2
Reward: Sword of Revealing
Light
Enemy 1: Mancubus
Enemy 2: Hell Knight
•printSummaryOfList: This method is a more
sophisticated type of print. Instead of merely printing out of the
full information of the list, it aggregates and collates the
information from the list into a more easily readable report. If
the list is empty,
print ”EMPTY LIST” without the quotation marks and a newline at the
end. The report determines the following pieces of
information:
1.The number of nodes in the
list.
2.The number of enemies, in total
in the list.
3.The number of rewards which are
healing to the player, that is if the reward has Healing or Health
in its name. You can assume that the case will match the specific
form of Healing or Health.
Therefore the output of this print operation takes the form
(considering the prior example as the list):
Number of Nodes: 2
Number of Enemies: 4
Number of Healing Rewards: 1
You are only allowed the use of the following libraries: string and iostream.
===================encounterNode.h=====================
#ifndef ENCOUNTER_NODE_H
#define ENCOUNTER_NODE_H
#include<iostream>
#include<string>
using namespace std;
class encounterNode
{
private:
string* enemies;
int numEnemies;
string reward;
public:
encounterNode* next;
encounterNode(string* list, int
numE, string re);
~encounterNode();
string* getEnemies() const;
void setEnemies(string* a, int
b);
string getEnemyAtIndex(int
a);
void setEnemyAtIndex(int a, string
b);
string getReward() const;
void setReward(string a);
int getNumEnemies() const;
void setNumEnemies(int a);
void print();
};
#endif
===================encounterNode.cpp=====================
#include "encounterNode.h"
#include<iostream>
#include<string>
using namespace std;
encounterNode::encounterNode(string* list, int numE, string
re)
{
enemies = list;
numEnemies = numE;
reward = re;
}
encounterNode::~encounterNode()
{
delete [] enemies;
}
string* encounterNode::getEnemies() const
{
return enemies;
}
void encounterNode::setEnemies(string* a, int b)
{
if (enemies != NULL)
delete[]enemies;
enemies = new string[b];
for (int i = 0; i < b; i++)
enemies[i] = a[i];
numEnemies = b;
}
string encounterNode::getEnemyAtIndex(int a)
{
if (a >= 0 && a < numEnemies)
return enemies[a];
else
return "";
}
void encounterNode::setEnemyAtIndex(int a, string b)
{
if (a >= 0 && a < numEnemies)
enemies[a] = b;
}
string encounterNode::getReward() const
{
return reward;
}
void encounterNode::setReward(string a)
{
reward = a;
}
int encounterNode::getNumEnemies() const
{
return numEnemies;
}
void encounterNode::setNumEnemies(int a)
{
numEnemies = a;
}
void encounterNode::print()
{
cout << "Number of Enemies: " <<
numEnemies << endl;
cout << "Reward: " << reward <<
endl;
for (int i = 0; i < numEnemies; i++)
{
cout << "Enemy " << (i
+ 1) << ": " << enemies[i] << endl;
}
cout << endl;
}
In: Computer Science
this won't compile
package com.test;
public class CatalogItem {
private String title;
private double price;
public CatalogItem(String title, double price) {
super();
this.title = title;
this.price = price;
}
public String getTitle() {
return title;
}
public double getPrice() {
return price;
}
}
//Book.java
package com.test;
public class Book extends CatalogItem {
private String author;
private int ISBN;
public Book(String title, double price, String author, int iSBN) {
super(title, price);
this.author = author;
ISBN = iSBN;
}
public String getAuthor() {
return author;
}
public int getISBN() {
return ISBN;
}
@Override
public String toString() {
return "Title: " + getTitle() + " | Author: "+author + " | Price: " + getPrice() + " ISBN: "+ISBN;
}
}
//AudioBook.java
package com.test;
public class AudioBook extends Book {
private double runningTime;
public AudioBook(String title, double price, String author, int iSBN, double runningTime) {
super(title, price, author, iSBN);
this.runningTime = runningTime;
}
public double getRunningTime() {
return runningTime;
}
public double getP() {
return getPrice()*0.90;
}
@Override
public String toString() {
return "Title: " + getTitle() + " | Author: "+getAuthor() + " | Price: " + getP() + " | ISBN: "+getISBN() + " | running time: "+runningTime;
}
}
//DVD.java
package com.test;
public class DVD extends CatalogItem {
private String director;
private int year;
private int dvdcode;
public DVD(String title, double price, String director, int year, int dvdcode) {
super(title, price);
this.director = director;
this.year = year;
this.dvdcode = dvdcode;
}
public String getDirector() {
return director;
}
public int getYear() {
return year;
}
public int getDvdcode() {
return dvdcode;
}
@Override
public String toString() {
return "Title: " + getTitle() + " | Director: "+director + " | Price: " + getPrice() + " | Year: "+year + " | DvdCode: "+dvdcode;
}
}
//Driver.java
package com.test;
import java.util.ArrayList;
import java.util.Scanner;
public class Driver {
public static ArrayList<Book> booklist = new ArrayList<>();
public static ArrayList<DVD> dvdlist = new ArrayList<>();
public static void display()
{
for(int i=0;i<booklist.size();i++)
{
if(booklist.get(i) instanceof AudioBook)
System.out.println((AudioBook)(booklist.get(i)));
else
System.out.println(booklist.get(i));
}
System.out.println("-------------------------------------------------------------------------------");
for(int i=0;i<dvdlist.size();i++)
{
System.out.println(dvdlist.get(i));
}
}
//method to find book
public static boolean findBook(int isbn)
{
for(int i=0;i<booklist.size();i++)
{
if(booklist.get(i).getISBN() == isbn)
return true;
}
return false;
}
//method to find book
public static boolean findDVD(int dvdcode)
{
for(int i=0;i<dvdlist.size();i++)
{
if(dvdlist.get(i).getDvdcode() == dvdcode)
return true;
}
return false;
}
public static void main(String[] args) {
System.out.println("Welcome to the comets Books and DVDs store(Catalog Section)");
int option;
String title;
double price;
String author;
int isbn;
double runningTime;
String director;
int year;
int dvdcode;
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Choose from the following option:");
System.out.println("1-Add Book");
System.out.println("2-Add AudioBook");
System.out.println("3-Add DVD");
System.out.println("4-Remove Book");
System.out.println("5-Remove DVD");
System.out.println("6-Display Catalog");
System.out.println("9-Exit Store");
option = sc.nextInt();
if(option == 1)
{
System.out.println("Please enter Book isbn");
isbn = sc.nextInt();
if(findBook(isbn))
continue;
System.out.println("Please enter Book title");
title = sc.next();
System.out.println("Please enter Book price");
price = sc.nextDouble();
while(price < 0) {
System.out.println("Please enter Book valid price");
price = sc.nextDouble();
}
System.out.println("Please enter Book author");
author = sc.next();
Book b = new Book(title, price, author, isbn);
booklist.add(b);
}
else if(option == 2)
{
System.out.println("Please enter Audio Book isbn");
isbn = sc.nextInt();
if(findBook(isbn))
continue;
System.out.println("Please enter Audio Book title");
title = sc.next();
System.out.println("Please enter Audio Book price");
price = sc.nextDouble();
while(price < 0) {
System.out.println("Please enter Audio Book valid price");
price = sc.nextDouble();
}
System.out.println("Please enter Audio Book author");
author = sc.next();
System.out.println("Please enter Audio Book running time");
runningTime = sc.nextDouble();
while(runningTime < 0) {
System.out.println("Please enter Audio Book valid running time");
runningTime = sc.nextDouble();
}
AudioBook b = new AudioBook(title, price, author, isbn,runningTime);
booklist.add(b);
}
else if(option == 3)
{
System.out.println("Please enter DVD code");
dvdcode = sc.nextInt();
if(findDVD(dvdcode))
continue;
System.out.println("Please enter DVD title");
title = sc.next();
System.out.println("Please enter DVD price");
price = sc.nextDouble();
System.out.println("Please enter DVD director");
director = sc.next();
System.out.println("Please enter DVD year");
year = sc.nextInt();
DVD d = new DVD(title, price, director, year, dvdcode);
dvdlist.add(d);
}
else if(option == 4)
{
System.out.println("Enter isbn number to delete book");
isbn = sc.nextInt();
boolean remove = false;
for(int i=0;i<booklist.size();i++){
if(booklist.get(i).getISBN() == isbn){
booklist.remove(i);
remove = true;
}
}
if(remove == false)
System.out.println("The Book doesn't exist in catalog");
display();
}
else if(option == 5)
{
System.out.println("Enter dvd code to delete DVD");
dvdcode = sc.nextInt();
boolean remove = false;
for(int i=0;i<dvdlist.size();i++){
if(dvdlist.get(i).getDvdcode() == dvdcode){
dvdlist.remove(i);
remove = true;
}
}
if(remove == false)
System.out.println("The DVD doesn't exist in catalog");
display();
}
else if(option == 6)
{
display();
}
else if(option == 9)
break;
else
System.out.println("This option is not acceptable");
}
}
}
In: Computer Science
In: Computer Science
1) Design an efficient data storage scheme using Normalization steps we have outlined.
2) Create tables as per normalization steps we have discussed in your database
Submit the table creation script and the output of desc
Explain any thing you wish to explain.
Data below:
invoiceno, invoice_date, invoice_amount, vendor, vendor_phone, vendor_address, vendor_preferred_payment_method, verification_date, verified_by, verifier_code, verifier_role_title, approval_date, approved_by, approver_code, approver_role_title, payment_date, payment_by, payer_code, payer_title 211,10/19/2019,2311.45,VIC,673-234-4001,"blah blah,nyc,ny",check:made payable to VIC:net 30d,10/20/2019,Shelley Cramer,SC,ECOM:Project manager,10/20/2019,Zack Swindler,ZS,Sales:Managing Director,10/21/2019,Cathy Zuppa, CZ, Finance:CPA 209,10/10/2019,28750.07,GRC,913-123-3489,"zing zing, Cool,CO",ACH:ABA23457892 FBO GRC:net 30d,10/10/2019,Zack Swindler,ZS,Sales:Managing Director,10/11/2019,Tiny Bulger, TB, COO,10/12/2019,Irwine Ladder,IL,Finance:CFO 203,10/4/2019,17000.45,NightCrawler,873-318-7777,"Blue Lagoon,Torch,AZ",check:made payable to NCH:net 60d,10/7/2019,Zack Swindler,ZS,Sales:Managing Director,10/8/2019,Shelley Cramer, SC, ECOM:Project Manager,10/12/2019,Cathy Zuppa, CZ, Finance:CPA 181,10/1/2019,2311.45,VIC,673-234-4001,"blah blah,nyc,ny",check:made payable to VIC:net 60d,10/2/2019,Zack Swindler,ZS,Sales:Managing Director,10/3/2019,Martin Short,MS,Sales:Managing Director,10/21/2019,Cathy Zuppa, CZ, Finance:CPA
In: Computer Science
Complete the following: (With Details and example if needed)
Given set S = {-3, -2, 0, 1, 2, 4}
Relation R is a relation on S such that R = { (?, ?) | ? ∈ ?, ? ∈ ? ??? ?? ≥ 1}
1. Using roster method, what is R?
2. Show the digraph representation of R
3. Show the matrix representation of R
4. if the relation does not have the property, give an example of why:
- Is R reflexive?
- Is R symmetric?
-Is R antisymmetric?
- Is R transitive?
In: Computer Science
A zombie picks up a calculator and starts adding odd whole numbers together, in order: 1 + 3 + 5......etc. You want to be able to determine the last number the zombie will add that will make the sum exceed some target number, such as "What will be the last number added that will make the sum on his calculator greater than 10,000?".
Write the MATLAB code necessary to solve this problem for the zombie or he will eat your brain. Create a function with an input of the target number (in the scenario given above the target number would be 10,000), which outputs the last numbered added.
In: Computer Science
In: Computer Science
Answer question in Python, show all code:
Write a program that calculates and displays the end of year balances in a savings account if $1,000 is put in the account at 6% interest for five years. For this problem, assume interest is calculated annually. (That is, if I put $1000 in a bank account at the beginning of the year, then the balance at the end of the year is $1,000 + $1,000*6%.) You may assume no money is removed from the account over this period.
Your program output should look like this:
Balance after year 1 is $ 1060.0
Balance after year 2 is $ 1123.6
Balance after year 3 is $ 1191.02
Balance after year 4 is $ 1262.48
Balance after year 5 is $ 1338.23
In: Computer Science
In: Computer Science
Sorting algorithm for arrays: understand how to perform the following algorithms. (a). Simple sorting
Bubblesort:T(n)ÎO(n2)
Selection sort : T(n) Î O(n2)
Insertion sort: T(n) Î O(n2)
(b).Advanced sorting
i. Shell sort: O(n2) < O(n1.25) < O(nlogn), O(n1.25) is empirical result for shell sort.
Merge sort: T(n) Î O(nlogn), need one temporary array with the same length as the array needed to be sorted.
Quick sort: -average case: T(n) Î O(nlogn),
-worst case(rare occurrence): T(n) Î O(n2)
5. Searching algorithm for arrays: understand how to perform the following algorithms. (a). Searching in unsorted arrays
i. Sequentialsearch
ii. Sequential search with sentinel
(b).Searching in sorted arrays
Binary search
Interpolation search
In: Computer Science
Why do think understanding the OSI Model is important from a work standpoint? Give an example.
In: Computer Science
How can I make this not add to the counter when the guess is right?
void guessGenerator(string hangmanStar, string
wordFromWordtxt)
{
char temp = '\0';
bool win = false;
int counter = 0;
while ((win == false) || (counter == 7))
{
char temp;
cout << hangmanStar <<
endl;
cout << "? ";
cin >> temp;
counter++;
for (int i = 0; i <
wordFromWordtxt.length(); i++)
{
if
(wordFromWordtxt.at(i) == temp)
{
hangmanStar.at(i) = temp;
}
}
if (wordFromWordtxt ==
hangmanStar)
{
win =
true;
cout <<
"You win." << endl;
cout <<
"The word was: " << hangmanStar << endl;
}
else if (counter == 7)
{
hangManPicture(counter);
cout <<
endl;
cout <<
"You lost" << endl;
cout <<
"Answer: " << wordFromWordtxt << endl;
return;
}
else
{
if
(hangmanStar.find(temp) == string::npos)
{
cout << endl;
cout << "Oops";
hangManPicture(counter);
cout << endl;
}
else
{
hangManPicture(counter);
cout << endl;
}
}
}
return;
}
In: Computer Science
Complete this programming problem in this assignment by using Microsoft Visual Studio Suite. Compile your solutions for each problem solved in a Word or Google document which includes (a) the pseudocode, (b) the C# codes and (c) the execution result (screen capture just the answer part using Snipping Tool, avoiding non-related or blank spaces). Notice for readability, that the (a) & (b) are in text mode and the (c) is in image mode. Use proper titles and wording in the results, such as Console.WriteLine("The total change to be made is {0:C}.", change); so that the results could be easily understood by a third party reader.
Question: Write a C# program to compute the profit made for
selling goldfish flakes online. The wholesale cost for a case of
24-boxes is $118. The price for sale with shipping charge is $9.59
per box. Shipping cost is $1.35 per box. The onlinelisting charge
is 12% of the customer payment. The payment processing cost is 4%
of the payment. Compute and display the following figures for
selling 25 cases of the products: the total wholesale cost for 25
cases; the total revenue for 25 cases of 24 boxes per case, the
total listing cost, the total payment processing cost, and the
total profit made.
In: Computer Science
In: Computer Science
1.
(a)
|
A. |
6.05 seconds |
|
|
B. |
4.05 seconds |
|
|
C. |
3.05 seconds |
|
|
D. |
none of the above |
(b) Review the car-caravan example in Section 1.4. Again assume a propagation speed of 100 km/hour. Suppose the caravan travels 200 km, beginning in front of one tollbooth, passing through a second tollbooth, and finishing just before a third tollbooth. Now suppose that when a car arrives at the second tollbooth, it proceeds through the tollbooth without waiting for the cars behind it. What is the end-to-end delay?
|
A. |
62 minutes |
|
|
B. |
124 minutes |
|
|
C. |
122 minutes and 12 seconds |
|
|
D. |
122 minutes and 24 seconds |
(c) We are sending a 30 Mbit MP3 file from a source host to a destination host. All links in the path between source and destination have a transmission rate of 10 Mbps. Assume that the propagation speed is 2*108 meters/sec, and the distance between source and destination is 10,000 km. Now suppose there is only one link between source and destination, and there are 10 FDM channels in the link. The MP3 file is sent over one of the channels. The end-to-end delay is ____.
|
A. |
30.05 seconds |
|
|
B. |
300 microseconds |
|
|
C. |
3 seconds |
|
|
D. |
none of the above |
(d) We are sending a 30 Mbit MP3 file from a source host to a destination host. All links in the path between source and destination have a transmission rate of 10 Mbps. Assume that the propagation speed is 2*108 meters/sec, and the distance between source and destination is 10,000 km. Now suppose there is only one link between source and destination. Also suppose that the entire MP3 file is sent as one packet. The transmission delay is ____.
|
A. |
3 seconds |
|
|
B. |
3.05 seconds |
|
|
C. |
50 milliseconds |
|
|
D. |
none of the above |
In: Computer Science