I am having issues using bool CustomerList::updateStore(). I am using strcpy in order to update input for the Store class, but all I am getting is the same input from before. Here is what I am trying to do:
Ex.
(1234, "Name", "Street Address", "City", "State", "Zip")
Using the function bool CustomerList::updateStore()
Updating..successful
New Address:
(1234, "Store", "111 Main St.", "Townsville", "GA", "67893")
CustomerList.h
#pragma once;
#include
#include "Store.h"
class CustomerList
{
public:
Store *m_pHead;
CustomerList();
~CustomerList();
bool addStore(Store *s);
Store *removeStore(int ID);
Store *getStore(int ID);
bool updateStore(int ID, char
*name, char *addr, char *city, char *st, char *zip);
void printStoresInfo();
};
CustomerList.cpp
#include
#include "CustomerList.h"
#include "Store.h"
using namespace std;
CustomerList::CustomerList()
{
m_pHead = NULL;
}
CustomerList::~CustomerList()
{
delete m_pHead;
}
bool CustomerList:: addStore(Store *s)
{
if(m_pHead==NULL)
{
m_pHead = new
Store(s->getStoreID(),s->getStoreName(),
s->getStoreAddress(), s->getStoreCity(),
s->getStoreState(), s->getStoreZip());
return true;
}
else
{
Store * temp;
temp=m_pHead;
while(temp->m_pNext != NULL)
{
temp =
temp->m_pNext;
}
temp->m_pNext = new Store(s->getStoreID(),s->getStoreName(), s->getStoreAddress(), s->getStoreCity(), s->getStoreState(), s->getStoreZip());
return true;
}
}
Store *CustomerList::removeStore(int ID)
{
Store *temp, *back;
temp = m_pHead;
back = NULL;
while((temp != NULL)&&(ID != temp ->getStoreID()))
{
back=temp;
temp=temp->m_pNext;
}
if(temp==NULL)
return NULL;
else if(back==NULL)
{
m_pHead = m_pHead
->m_pNext;
return temp;
}
else
{
back -> m_pNext = temp->
m_pNext;
return temp;
}
return NULL;
}
Store *CustomerList::getStore(int ID)
{
Store *temp;
temp = m_pHead;
while((temp != NULL) && (ID != temp ->getStoreID()))
{
temp =
temp->m_pNext;
}
if(temp == NULL)
return NULL;
else
{
Store *retStore = new
Store();
*retStore = *temp;
retStore->m_pNext = NULL;
return retStore;
}
}
bool CustomerList::updateStore(int ID, char *name, char *addr, char *city, char *st, char *zip)
{
Store *temp;
temp = m_pHead;
while((temp!=
NULL)&&(ID != temp->getStoreID()))
{
temp = temp->m_pNext;
}
if(temp == NULL)
{
return false;
}
else
{
strcpy(temp->getStoreName(),name);
strcpy(temp->getStoreAddress(),addr);
strcpy(temp->getStoreCity(),city);
strcpy(temp->getStoreState(),st);
strcpy(temp->getStoreZip(),zip);
return
true;
}
}
void CustomerList::printStoresInfo()
{
Store *temp;
if(m_pHead == NULL)
{
cout << " The List is
empty.\n" ;
}
else
{
temp = m_pHead;
while(temp != NULL)
{
temp->printStoreInfo();
temp = temp->m_pNext;
}
}
}
Store.h
#pragma once;
#include
#include
using namespace std;
class Store
{
private:
int
m_iStoreID;
char
m_sStoreName[64];
char
m_sAddress[64];
char m_sCity[32];
char
m_sState[32];
char m_sZip[11];
public:
Store *m_pNext;
Store();
// Default constructor
Store(int ID,
// Constructor
char
*name,
char
*addr,
char
*city,
char *st,
char
*zip);
~Store();
// Destructor
int getStoreID();
// Get/Set
store ID
void setStoreID(int ID);
char *getStoreName();
// Get/Set store name
void setStoreName(char
*name);
char
*getStoreAddress(); // Get/Set store
address
void setStoreAddress(char
*addr);
char *getStoreCity();
// Get/Set store city
void setStoreCity(char
*city);
char *getStoreState();
// Get/Set store state
void setStoreState(char
*state);
char *getStoreZip();
// Get/Set store zip
code
void setStoreZip(char *zip);
void printStoreInfo();
// Print all info on this
store
};
Store.cpp
#include "Store.h"
#include
using namespace std;
Store::Store()
{
m_pNext = NULL;
}
Store::Store(int ID, char *name, char *addr, char *city, char *st,
char *zip)
{
m_iStoreID = ID;
strcpy(m_sStoreName, name);
strcpy(m_sAddress, addr);
strcpy(m_sCity, city);
strcpy(m_sState, st);
strcpy(m_sZip, zip);
m_pNext = NULL;
}
Store::~Store()
{
// Nothing to do here
}
int Store::getStoreID()
{
return m_iStoreID;
}
void Store::setStoreID(int ID)
{
m_iStoreID = ID;
}
char *Store::getStoreName()
{
char *name = new char[strlen(m_sStoreName) + 1];
strcpy(name, m_sStoreName);
return name;
}
void Store::setStoreName(char *name)
{
strcpy(m_sStoreName, name);
}
char *Store::getStoreAddress()
{
char *addr = new char[strlen(m_sAddress) + 1];
strcpy(addr, m_sAddress);
return addr;
}
void Store::setStoreAddress(char *addr)
{
strcpy(m_sAddress, addr);
}
char *Store::getStoreCity()
{
char *city = new char[strlen(m_sCity) + 1];
strcpy(city, m_sCity);
return city;
}
void Store::setStoreCity(char *city)
{
strcpy(m_sCity, city);
}
char *Store::getStoreState()
{
char *state = new char[strlen(m_sState) + 1];
strcpy(state, m_sState);
return state;
}
void Store::setStoreState(char *state)
{
strcpy(m_sState, state);
}
char *Store::getStoreZip()
{
char *zip = new char[strlen(m_sZip) + 1];
strcpy(zip, m_sZip);
return zip;
}
void Store::setStoreZip(char *zip)
{
strcpy(m_sZip, zip);
}
void Store::printStoreInfo()
{
cout << m_iStoreID << setw(20) <<
m_sStoreName << setw(15) << m_sAddress
<< setw(15) << m_sCity
<< ", " << m_sState << setw(10) << m_sZip
<< "\n";
}
Employee Record.h
#pragma once
#include "CustomerList.h"
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
CustomerList
*getCustomerList();
CustomerList
*m_pCustomerList;
//The default
constructor
EmployeeRecord();
EmployeeRecord(int ID, char *fName,
char *lName, int dept, double sal);
~EmployeeRecord();
int getID();
void setID(int ID);
void getName(char *fName, char *lName);
void setName(char *fName, char *lName);
int getDept();
void setDept(int d);
double getSalary();
void setSalary(double sal);
void printRecord();
};
Employee Record.cpp
#include
#include "EmployeeRecord.h"
#include "CustomerList.h"
using namespace std;
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the
following
m_iEmployeeID = 0;
m_sFirstName[0] = '\0';
m_sLastName[0] = '\0';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName,
int dept, double sal)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
m_iEmployeeID = ID;
m_iDeptID = dept;
m_dSalary = sal;
fName = NULL;
lName = NULL;
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
delete m_pCustomerList;
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
strcpy(fName, m_sFirstName);
strcpy(lName, m_sLastName);
}
void EmployeeRecord::setName(char *fName, char *lName)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
}
int EmployeeRecord::getDept()
{
return m_iDeptID;
}
void EmployeeRecord::setDept(int d)
{
m_iDeptID = d;
}
double EmployeeRecord::getSalary()
{
return m_dSalary;
}
void EmployeeRecord::setSalary(double sal)
{
m_dSalary = sal;
}
void EmployeeRecord::printRecord()
{
cout << "ID: " << m_iEmployeeID << "\t";
cout << "\tName: " << m_sLastName <<
" , " << m_sFirstName << "\t";
cout << "\tDept: " << m_iDeptID <<
"\t" << "\t";
cout << "Salary: $" << m_dSalary <<
"\t" << endl << endl;
}
CustomerList *EmployeeRecord::getCustomerList()
{
CustomerList *m_pCustomerList = new
CustomerList();
return m_pCustomerList;
}
MainProgram.cpp
#include
#include "EmployeeRecord.h"
#include
using namespace std;
int main()
{
int employee_id = 100, dept_id = 42, IDNum;
char fname [32];
char lname [32];
double salary = 65000;
double salaryp;
double *p_salary ;
salaryp = 65000;
p_salary = &salaryp;
//=========================================================================EmployeeRecord
Testing==========================================================================================
EmployeeRecord *Employee1 = new
EmployeeRecord(dept_id, fname, lname, dept_id, salary);
Employee1->setID(employee_id);
Employee1->setName("John", "Doe");
Employee1->setDept(42);
Employee1->setSalary(salary);
IDNum = Employee1-> getID();
Employee1->getName(fname,lname);
Employee1->getDept();
Employee1->getSalary();
if(IDNum == employee_id)
//Test Successful
if((strcmp(fname, "John") ==
0)&&(strcmp(lname,"Doe") == 0))
//Test Successful
if(dept_id == 42)
//Test Successful
if(*p_salary == salary)
//Test Successful
Employee1->printRecord();
Employee1->setID(456);
Employee1->setName("Jane", "Smith");
Employee1->setDept(45);
Employee1->setSalary(4000);
IDNum = Employee1-> getID();
Employee1->getName(fname,lname);
Employee1->getDept();
Employee1->getSalary();
if(IDNum == 456)
//Test Successful
if((strcmp(fname, "Jane") ==
0)&&(strcmp(lname,"Smith") == 0))
//Test Successful
if(dept_id == 45)
//Test Successful
if(*p_salary == 4000)
Employee1->printRecord();
//=====================================Customer List Testing====================================
cout
<<"\n==============================================================================================================="
<< endl;
cout <<" Adding stores to the list "
<< endl;
cout
<<"==============================================================================================================="
<< endl << endl;
CustomerList *cl = Employee1
->getCustomerList();
//----Testing the addStore, and printStoresInfo
functions:--------------------------------------
Store *s = new Store(4567,"A Computer Store", "1111
Main St." ,"West City" ,"Alabama", "12345");
Store *s1 = new Store(7654,"Jones Computers", "1234
Main St." ,"North City" ,"Alabama", "54321");
Store *s2 = new Store(1234, "Smith Electronics", "2222
2nd St." ,"Eastville", "Alabama","12346");
cout <<"Calling printStoresInfo() after adding
one store to list."<< endl;
cout
<<"\n==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl -> addStore(s);
cl -> printStoresInfo();
cout
<<"==============================================================================================================="
<< endl << endl;
cout <<"Calling printStoresInfo() after
adding second store to list."<< endl;
cout
<<"\n==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl -> addStore(s1);
cl -> printStoresInfo();
cout
<<"==============================================================================================================="
<< endl<< endl;
cout <<"Calling printStoresInfo() after adding
third store to list."<< endl;
cout
<<"\n==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl -> addStore(s2);
cl -> printStoresInfo();
cout
<<"==============================================================================================================="
<< endl << endl;
//---Testing the get store function:---------
Store *s3 = NULL;
s3=cl->getStore(1234);
if((s3 != NULL) && (s3->getStoreID() ==
1234))
cout << "Testing
getStore(1234)...successful" << endl;
Store *s4 = NULL;
s4=cl->getStore(7654);
if((s4 != NULL) && (s4->getStoreID() ==
7654))
cout << "Testing
getStore(7654)...successful" << endl;
cout << "Testing getStore(9999)..." <<
endl;
Store *s9 = NULL;
s9 = cl->getStore(9999);
if(s9 == NULL)
cout << "getStore() correctly
reported failure to find the store." << endl;
//-------------------------------------------
//---Testing updateStore Function:
----------------------------------------------------------------------
bool chk = cl->updateStore(1234, "hello", "1111
TestAddress", "TestCity", "TestState", "TestZip");
if(chk)
{
cout
<<"\n==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl ->printStoresInfo();
cout
<<"==============================================================================================================="
<< endl;
}
else
cout << "updateStore test
failed\n";
bool chk1 = cl -> updateStore(9999, "NoName", "1111 NoAddress", "NoCity", "NoState", "NoZip");
if(!chk1)
cout << "updateStore negative
test passed.\n";
else
cout << "updateStore negative
test failed.\n";
//---------------------------------------------------------------------------------------------------------
//--Testing the removeStore function-------------------------------------------------------------------------------------------------
Store *s5;
s5 = cl ->removeStore(4567);
if(s5 == NULL)
Store *s5 = cl -> removeStore(4567);
if(( s5 != NULL) &&
(s5->getStoreID() == 4567))
cout << "\nRemoving store 4567 from the
list...successful" << endl;
cout << "Calling printStoresInfo after deleting
a store from the head of the list." << endl;
cout
<<"==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl -> printStoresInfo();
cout
<<"==============================================================================================================="
<< endl << endl;
Store *s6;
s6 = cl ->removeStore(1234);
if(s6 == NULL)
Store *s6 = cl -> removeStore(1234);
if(( s6 != NULL) && (s6->getStoreID() ==
1234))
cout << "\nRemoving store 1234 from the
list...successful" << endl;
cout << "Calling printStoresInfo after deleting
a store from the head of the list." << endl;
cout
<<"==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl -> printStoresInfo();
cout
<<"==============================================================================================================="
<< endl << endl;
Store *s7;
s7 = cl ->removeStore(7654);
if(s7 == NULL)
Store *s7 = cl -> removeStore(7654);
if(( s7 != NULL) &&
(s7->getStoreID() == 7654))
cout << "\nRemoving store 7654 from the
list...successful" << endl;
cout << "Calling printStoresInfo after deleting
a store from the head of the list." << endl;
cout
<<"==============================================================================================================="
<< endl;
cout << " Stores in List " <<
endl;
cout
<<"==============================================================================================================="
<< endl;
cl -> printStoresInfo();
cout
<<"==============================================================================================================="
<< endl << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---Testing the
destructor-----------------
EmployeeRecord *e = new
EmployeeRecord();
delete e;
//------------------------------------------
system ("pause");
return 0;
}
In: Computer Science
The syntax of a language is quite simple. The alphabet of the
language is {a, b, d, #} where # stands for a space. The grammar
is
<sentence> → <word> | <sentence> #
<word>
<word> → <syllable> | <syllable> <word>
<syllable>
<syllable> → <plosive> | <plosive> <stop> |
a <plosive> | a <stop>
<plosive> → <stop> a
<stop> → b | d
Which of the following speakers is an imposter? An impostor does
not follow the rules of the language.
a: ba#ababadada#bad#dabbada Chimp:
b: abdabaadab#ada
c: Baboon: dad#ad#abaadad#badadbaad
In: Computer Science
In GoogleCollab (Python)
In: Computer Science
add the following numbers using 16-bit 2's complement.
show all the steps and calculations.
Please also show steps to verify that the answer is correct.
2368 and -772
In: Computer Science
Need hep with this c++ program
Declare an array of integers of size 8 and initialize it with any non-duplicate integer values you like. Don’t enter the values in any order. Print the unsorted array. Sort the array using selection sort or insertion sort in descending order. Print what sort you are using. Write any additional functions that you need for sorting. Keep monitoring the number of comparisons and number of swaps performed while sorting. Report both after sorting. Print the sorted array.
In: Computer Science
JAVA
Design and implement a class called Boxthat represents a 3-dimensional box.1.Instance DataYour Box class will need variables to store the size of the box. All of these variables will be of type ‘private double’.•width•height•depthYour Boxclass will also need a variable to keep track of whether or not the box is full. This will be of type ‘private boolean’.•full2.ConstructorDeclaration: public Box( double width, double height, double depth)•Your Boxconstructor will accept the width, height,and depthof the box.•In your constructor, initialize the width, height,and depthinstance variables to values passed in as parameters to the constructor.•Each newly created box will be empty. This means that you will also need to initialize fullto false in your constructor.3.Getter and Setter MethodsInclude getter and setter methods for all instance data. We will assume that all supplied dimension values are positive values. Here is an example of the method declarations for width to get you started.•Getter: public double getWidth()•Setter: public void setWidth(double width)4.Public Methods•Write a public double volume()method that will calculate and return the volume of the box based on the instance data values.•Write a public double surfaceArea()method that will calculate and return the surface area of the box based on the instance data values.5.toString MethodWrite apublic String toString() method that returns a one-line description of the box. The description should provide its dimensions and whether or not the box is full. Format all double values to 2 decimal places.Example: An empty 4.00x 5.00 x 2.00 box.Part 2: Testing your ClassNow, create a driver class called BoxTestand do the following in the main method.Create your first box1.Create a Boxvariable called smallBoxand instantiate it with width 4, height 5, and depth 2.2.Print the one-line description of smallBoxusing its toString()method.3.Confirm that smallBox’s width, height, and depth getter methods are returning the correct values.4.Confirm that smallBox’s volume()and surfaceArea()methods are returning the correct values.5.Use smallBox’s setter methods to change it from “empty” to “full” and to change its dimension values to width 2, height 3, and depth 1.6.Print the one-line description of smallBoxusing toString()again, and confirm that all changed values are reflected.7.Confirm that all getter and other methods return the correct values reflecting smallBox’s current dimensions and full value.Create several boxes and find the largest oneDo not delete what you did above! Add the following code to the end of your BoxTestclass.1.Declare and instantiate an ArrayListobject that will store your Boxobjects.See the listing below as a sample of how to use the ArrayListbut with Stringobjects.2.In a standard “for” loop that iterates 5 times, create a new Boxwith randomly generated width, height, and depth and add the box to your ArrayList. Limit dimension values to a reasonable range. Randomly generate a Boolean value and use it to call the Box’s method for setting “full” (use the nextBoolean()method in the Randomclass).3.In the loop, print outthe Box’s details, labeled according to the loop iteration (i.e. if this isthe first iteration of the loop, label the box as “Box 1: “ in the output).4.Use a for-each loop(as shown in the listing above)to find the Boxwith the largest volume. You will need to declare a largest box variable of type Boxto keep track of the largest box. This variable needs to be declared outside of the loop so that it will still be available when the loop ends. Use conditional statements inside the loop to compare the current Box to the largest Box, so far, and update the largest box variable when appropriate.5.After the loop, print the details of the largest Box. Confirm that you program identified the correct boxes.
In: Computer Science
create a program that will calculate a student s grade in a class that uses a weighted gradebook
In: Computer Science
Question 3: Write the following Java program.
A. Create a class called Quadrilateral that contains the following: [4 Marks]
• Five double type data fields for: side1, side2, side3, side4, and perimeter
• A no-argument constructor that creates a Quadrilateral with all sides equal to 1
• Methods named setSide1(double s1), setSide2(double s2), setSide3(double s3), and
setSide4(double s4) to set the values of the four sides
• A method named calculatePerimeter( ) to calculate and return the perimeter of the
quadrilateral
B. Create a child class called Square that contains a method named calculateArea() to
calculate the area of the Square. [2 Marks]
C. Create a java main class named TestQuad to do the following: [4 Marks]
• Create a Quadrilateral object named Quad1 and a Square object named Sq1.
• Call the methods setSide1(double s1), setSide2(double s2), setSide3(double s3), and
setSide4(double s4) to:
o set the sides of Quad1 to 10, 20, 25, and 30, respectively
o set all sides of Sq1 to 3
• Display the perimeter of Quad1 by calling the method calculatePerimeter ( ). Display
the perimeter of Sq1 by calling the method calculatePerimeter ( ).
• Display the area of Sq1 by calling the method calculateArea()
Hint: Perimeter = sum of all sides & Area of Square = side * side
In: Computer Science
JAVA - Write a program that prompts the user (at the command line) for 4 positive integers, then draws a pie chart in a window. Convert the numbers to percentages of the numbers’ total sum; color each segment differently; use Arc2D. No text fields (other than the window title) are required. Provide a driver in a separate source file to test your class.
Please use the following:
java.lang.Object
java.awt.Graphics
java.awt.Graphics2D
Take note of the following:
setPaint
setStroke
fill
// imports
public class PieChartPanel extends JPanel {
// attributes
// constructor
public void paintComponent(Graphics g) {
super.paintComponent (g);
Graphics2D g2d = ( Graphics2D ) g;
...
}
There should be a paintComponent method that calls its parent
In: Computer Science
Computer Science Multiple Choice: Please complete all 5 questions in exchange for an immediate upvote. Incomplete answers will be downvoted so please move on if they aren't worth your time. Thank you!
In: Computer Science
Note: The built-in character analysis functions
(isdigit(), islower(),
etc.) may not be used.
Exercise 6.1 Write to an output file
Open an output file (stream) and write your identifying information
to the
associated output file using a function. Put your standard output
informa-
tion in a function named ShowHeader(). The file stream must be
passed by
reference to the function. To do this, an & (ampersand) is used
between the
data type (ofstream) and the name of the argument (I like to use
fOut for
output file stream objects and fIn for input file stream object
names).
Exercise 6.2 Read from an input file
Read/Process an input file a character at a time. Open an input
file (stream)
and read a single character on each pass through a loop (a while()
loop is
probably easiest) until the end of file is reached. After reading
the character,
write it to the output file created earlier. The output should
contain the
same characters as the input file.
Exercise 6.3 Character Analysis
Suggestion: Develop the remainder of this program in piecewise
manner–
specifically, add one character analysis operation at a time,
before adding
the next.
Analyze the characters in a file using functions to display their
charac-
teristics, e.g., lower case, digit etc. The logic for analysis will
be inside the
loop above.
Specifically, test if the character:
• is a letter.
• test if it is lower case or upper case.
• if the character is a letter, test if it is a vowel or
consonant.
• is a digit.
• if the character is a digit, test if the value is odd or
even.
• is a punctuation character.
• is a logical operator symbol.
Write a short function for most operations in the list above. If a
character
is a letter, then it is either upper or lower case, so we only need
to write one
function to test the case of the character. Do not use the built-in
functions.
Note: there are no I/O (input/output) operations in
the functions, only a
single character is examined.
In: Computer Science
Describe a simple SIMD architecture for “Image processing” application.
In: Computer Science
Hi
I have an assignment that has this question basis on network protocols (multiple access protocols):
Q1 ) Explain why collision is an issue in random access protocols but not in channelization protocols?
I need an explanision for that question
In: Computer Science
Discuss in what areas of your organization, or an organization you are familiar with, should conduct association analysis. With what data objects should the organization attempt to discover relationships to other data objects. What would be the business benefits of uncovering these relationships?
In: Computer Science
Experiment with a simple derivation relationship between two classes. Put println statements in constructors of both the parent and child classes. Do not explicitly call the constructor of the parent in the child. What happens? Why? Change the child’s constructor to explicitly call the constructor of the parent. Now what happens?
In: Computer Science