Question

In: Computer Science

I need C++ programming with output. I have tried other programming and it does not work....

I need C++ programming with output. I have tried other programming and it does not work. So please give me the one that actually works.

Assignment 1

Design your own linked list class that works as a template class. It should provide member functions for appending, inserting and deleting nodes. The destructor should destroy the list. The class should also provide a member function that will display the contents of the list to the screen. The class should also provide a member function to search the list for an element in the list. The search should return the index (location) of the item in the list. So if it is the first element in the list then it should return 0. If the item is not in the list, it should return -1. Have main create two instances of the linked list with different data types and show that all of the functions work correctly.

Assignment 2

In this program you will use the linked list created in Assignment 1. First you will create a class that holds information about the weather for a given month which should be called WeatherStats. It should have data members that are doubles to hold the amount of rain for the month and the amount of snow for the month. It will also have a data member that holds the number of sunny days during the month. It should provide accessors and mutators for the private data members. Main will create an instance of the linked list with a data type of the WeatherStats (LinkedList). The program should ask the user for how many months they wish to enter weather statistics for. The program will then prompt the user for that information (rain, snow and sunny days). The data needs to be stored in the WeatherStats class and it should be appended to the linked list. Main must then call a function that displays the data in the list; this function will call the display function in the linked list. Main will call a function that determines the month with the largest and smallest amount of rain, snow and sunny days. This function should not be part of the linked list. It should appear in the same file as main. A function will need to be added to the linked list that provides an item from the list. The function in the linked list will return the object stored in the list. The function in main will need to request each item in the list one at a time. Another solution is to create a derived class of the linked list, which does all of the work for finding the largest and smallest.

Solutions

Expert Solution

ASSIGNMENT 1:::
=============

#include <iostream>
using namespace std;

template <class DataType>
struct Node
{
DataType data;
Node<DataType> *next;

};

template <class DataType>
class LinkedList
{
public:
LinkedList();
LinkedList (const LinkedList<DataType> & applist);
~LinkedList();
LinkedList<DataType> & operator = (const LinkedList<DataType> & rmlist);
void insert (const DataType & element);
bool first (DataType & listEll);
inline bool getNext (DataType & listEll);
int find (const DataType & element);
bool retrieve (DataType & element);
bool remove (DataType & element);
bool isEmpty() const;
void makeEmpty();

void print();
private:
Node<DataType> *start;
Node<DataType> *end;
Node<DataType> *current;
inline void deepCopy (const LinkedList<DataType> & real);
};

template <class DataType>
void LinkedList<DataType>::print()
{
Node<DataType>* curr = start;
cout<<"START --> ";
while (curr)
{
cout<<curr->data<<" --> ";
curr = curr->next;
}
cout<<"NULL"<<"\n\n";
}

template <class DataType>
LinkedList<DataType>::LinkedList()
: start(0), current(0) , end(0){}

template <class DataType>
LinkedList<DataType>::LinkedList (const LinkedList<DataType> & applist)
{
deepCopy( applist );
}

template <class DataType>
LinkedList<DataType>::~LinkedList()
{
makeEmpty( );
}

template <class DataType>
LinkedList<DataType> & LinkedList<DataType>::operator = (const LinkedList<DataType> & rmlist)
{
if (this == &rlist)
return *this;
makeEmpty();
deepCopy (rmlist);
return *this;
}

template <class DataType>
void LinkedList<DataType>::insert(const DataType& parameter)
{
current = 0;
Node<DataType>* node = new Node<DataType>;
node->data = parameter;

if (!start)
{
start = node;
end = node;
return;
}

end->next = node;
end=end->next;
end->next = 0;
}

template <class DataType>
bool LinkedList<DataType>::first(DataType& parameter)
{
if (!start) return false;
parameter = start->data;
current = start;
return true;
}

template <class DataType>
bool LinkedList<DataType>::getNext(DataType& parameter)
{
if (!current) return false;
current = current->next;
if (!current) return false;
parameter = current->data;
return true;
}

template <class DataType>
int LinkedList<DataType>::find(const DataType& parameter)
{
int position = -1;
DataType temp;
if (first(temp)) do
{
++position;
if (parameter == temp)
return position;
} while (getNext(temp));
return position;
}

template <class DataType>
bool LinkedList<DataType>::retrieve(DataType& parameter)
{
if (find(parameter) == -1)
return false;
parameter = current->data;
return true;
}

template <class DataType>
bool LinkedList<DataType>::remove(DataType& parameter)
{
Node<DataType>* p;
Node<DataType>* pre;
for (pre = 0, p = start; p; pre = p, p = p->next)
if (p->data == parameter)
break;
  
if (!p) return false;
if (pre) pre->next = p->next; else start = p->next;
if (p == current) current = current->next;
parameter = p->data;
delete p;
return true;
}

template <class DataType>
bool LinkedList<DataType>::isEmpty() const
{
return start == 0;
}

template <class DataType>
void LinkedList<DataType>::makeEmpty()
{
while (start)
{
current = start->next;
delete start;
start = current;
} }

template <class DataType>
inline void LinkedList<DataType>::deepCopy( const LinkedList<DataType> & real )
{
start = current = NULL;
if ( original.start == NULL )
return;
Node<DataType> *copyptr = start = new Node<DataType>;
Node<DataType> *realptr = real.start;
copyptr->data = realptr->data;
if ( realptr == real.current )
current = copyptr;
while (realptr->next != NULL ) {
realptr = originalptr->next;
copyptr->next = new Node<DataType>;
copyptr = copyptr->next;
copyptr->data = realptr->data;
if ( realptr == real.current )
current = copyptr;
}
copyptr->next = NULL;
}
  
int main()
{
int remove, n;
cout<<"First linked list of INTEGERS: \n\n";
LinkedList<int> ll_Int = LinkedList<int>();
ll_Int.insert(1);
ll_Int.insert(2);
ll_Int.insert(3);
ll_Int.insert(4);
ll_Int.insert(5);

remove=3;
ll_Int.remove(remove);

ll_Int.print();

n = 2;
cout<<"\nPosition of ("<<n<<") in the array :"<<(ll_Int.find(n))<<"\n\n";

  
//creating second linked list of datatype char
char r, n1;
cout<<"\n\nSecond linked list of CHARACTERS: \n\n";
LinkedList<char> ll_Char = LinkedList<char>();
ll_Char.insert('a');
ll_Char.insert('b');
ll_Char.insert('c');
ll_Char.insert('d');
ll_Char.insert('e');

r='c';
ll_Char.remove(r);

ll_Char.print();

n1 = 'a';
cout<<"\nPosition of ("<<n1<<") in the array :"<<(ll_Char.find(n1))<<"\n\n";

return 0;
}

ASSIGNMENT 2

#include <iostream>
#include<string>
#include <iomanip>
using namespace std;

template <class DataType>
struct Node
{
DataType data;
Node<DataType> *next;

};

template <class DataType>
class LinkedList
{
public:
Node<DataType> *start;

LinkedList();
LinkedList (const LinkedList<DataType> & applist);
~LinkedList();
LinkedList<DataType> & operator = (const LinkedList<DataType> & rmlist);
void insert (const DataType & element);
bool first (DataType & listEll);
inline bool getNext (DataType & listEll);
int find (const DataType & element);
bool retrieve (DataType & element);
bool remove (DataType & element);
bool isEmpty() const;
void makeEmpty();

void print();
private:
  
Node<DataType> *end;
Node<DataType> *current;
inline void deepCopy (const LinkedList<DataType> & real);
};

template <class DataType>
void LinkedList<DataType>::print()
{
Node<DataType>* curr = start;
cout<<"START --> ";
while (curr)
{
cout<<curr->data<<" --> ";
curr = curr->next;
}
cout<<"NULL"<<"\n\n";
}

template <class DataType>
LinkedList<DataType>::LinkedList()
: start(0), current(0) , end(0){}

template <class DataType>
LinkedList<DataType>::LinkedList (const LinkedList<DataType> & applist)
{
deepCopy( applist );
}

template <class DataType>
LinkedList<DataType>::~LinkedList()
{
makeEmpty( );
}

template <class DataType>
LinkedList<DataType> & LinkedList<DataType>::operator = (const LinkedList<DataType> & rmlist)
{
if (this == &rmlist)
return *this;
makeEmpty();
deepCopy (rmlist);
return *this;
}

template <class DataType>
void LinkedList<DataType>::insert(const DataType& parameter)
{
current = 0;
Node<DataType>* node = new Node<DataType>;
node->data = parameter;

if (!start)
{
start = node;
end = node;
end->next = 0;
return;
}

end->next = node;
end=end->next;
end->next = 0;
}

template <class DataType>
bool LinkedList<DataType>::first(DataType& parameter)
{
if (!start) return false;
parameter = start->data;
current = start;
return true;
}

template <class DataType>
bool LinkedList<DataType>::getNext(DataType& parameter)
{
if (!current) return false;
current = current->next;
if (!current) return false;
parameter = current->data;
return true;
}

template <class DataType>
int LinkedList<DataType>::find(const DataType& parameter)
{
int position = -1;
DataType temp;
if (first(temp)) do
{
++position;
if (parameter == temp)
return position;
} while (getNext(temp));
return position;
}

template <class DataType>
bool LinkedList<DataType>::retrieve(DataType& parameter)
{
if (find(parameter) == -1)
return false;
parameter = current->data;
return true;
}

template <class DataType>
bool LinkedList<DataType>::remove(DataType& parameter)
{
Node<DataType>* p;
Node<DataType>* pre;
for (pre = 0, p = start; p; pre = p, p = p->next)
if (p->data == parameter)
break;
  

if (!p) return false;
if (pre) pre->next = p->next; else start = p->next;
if (p == current) current = current->next;
parameter = p->data;
delete p;
return true;
}

template <class DataType>
bool LinkedList<DataType>::isEmpty() const
{
return start == 0;
}

template <class DataType>
void LinkedList<DataType>::makeEmpty()
{
while (start != end)
{
current = start->next;
delete start;
start = current;
}
delete start;
}

template <class DataType>
inline void LinkedList<DataType>::deepCopy( const LinkedList<DataType> & real )
{
start = current = NULL;
if ( real.start == NULL )
return;
Node<DataType> *copyptr = start = new Node<DataType>;
Node<DataType> *realptr = real.start;
copyptr->data = realptr->data;
if ( realptr == real.current )
current = copyptr;
while ( realptr->next != NULL ) {
realptr = realptr->next;
copyptr->next = new Node<DataType>;
copyptr = copyptr->next;
copyptr->data = realptr->data;
if ( realptr == real.current )
current = copyptr;
}
copyptr->next = NULL;
}
  
class WeatherStats
{
private:
string month;
double amntRainPerMonth;
double amntSnowPerMonth;
int sunnyDayPerMonth;

public:
WeatherStats()
{
amntRainPerMonth = 0;
amntSnowPerMonth = 0;
sunnyDayPerMonth = 0;
month = "";
}

string getMonth()
{
return month;
}
double getAmntRainPerMonth()
{
return amntRainPerMonth;
}

double getAmntSnowPerMonth()
{
return amntSnowPerMonth;
}

double getSunnyDayPerMonth()
{
return sunnyDayPerMonth;
}

void setMonth(string d)
{
month = d;
}
void setAmntRainPerMonth(double d)
{
amntRainPerMonth = d;
}

void setAmntSnowPerMonth(double d)
{
amntSnowPerMonth = d;
}

void setSunnyDayPerMonth(int d)
{
sunnyDayPerMonth = d;
}

};

void print(LinkedList<WeatherStats> &ll_stats)
{
Node<WeatherStats> *temp = ll_stats.start;

cout<<"\nStats: \n\n";
cout<<setw(20)<<"Month"<<setw(15)<<" Amount Of Rain"<<setw(15)<<" Amount Of Snow"<<setw(15)<<" SunnyDays\n\n";
while (temp)
{
cout<<setw(20)<<temp->data.getMonth()<<setw(15)<<temp->data.getAmntRainPerMonth()<<setw(15)<<temp->data.getAmntSnowPerMonth()<<setw(15)<<temp->data.getSunnyDayPerMonth()<<"\n";

temp=temp->next;
}

  
}

void calculate(LinkedList<WeatherStats> &ll_stats)
{
Node<WeatherStats> *temp = ll_stats.start;

cout<<"\n\nCalculations: \n\n";
string maxMonth, minMonth;

double maxRain, minRain;

maxRain = temp->data.getAmntRainPerMonth();
minRain = maxRain;

  

maxMonth = minMonth = temp->data.getMonth();

while (temp)
{
if(temp->data.getAmntRainPerMonth() < minRain)
{
minRain = temp->data.getAmntRainPerMonth();
minMonth = temp->data.getMonth();
}
if(temp->data.getAmntRainPerMonth() > maxRain)
{
maxRain = temp->data.getAmntRainPerMonth();
maxMonth = temp->data.getMonth();
}
temp=temp->next;
}

cout<<"Maximum rain :"<<maxRain<<" in month: "<<maxMonth<<"\n";
cout<<"Minimum rain :"<<minRain<<" in month: "<<minMonth<<"\n";
//////////////////////
temp = ll_stats.start;
double maxSnow, minSnow;

maxSnow = temp->data.getAmntSnowPerMonth();
minSnow = maxSnow;

  

maxMonth = minMonth = temp->data.getMonth();

while (temp)
{
if(temp->data.getAmntSnowPerMonth() < minSnow)
{
minSnow = temp->data.getAmntSnowPerMonth();
minMonth = temp->data.getMonth();
}
if(temp->data.getAmntSnowPerMonth() > maxSnow)
{
maxSnow = temp->data.getAmntSnowPerMonth();
maxMonth = temp->data.getMonth();
}
temp=temp->next;
}

cout<<"Maximum snow :"<<maxSnow<<" in month: "<<maxMonth<<"\n";
cout<<"Minimum snow :"<<minSnow<<" in month: "<<minMonth<<"\n";

//////////////////////
temp = ll_stats.start;
int maxSunny, minSunny;

maxSunny = temp->data.getSunnyDayPerMonth();
minSunny = maxSunny;

  

maxMonth = minMonth = temp->data.getMonth();

while (temp)
{
if(temp->data.getSunnyDayPerMonth() < minSunny)
{
minSunny = temp->data.getSunnyDayPerMonth();
minMonth = temp->data.getMonth();
}
if(temp->data.getSunnyDayPerMonth() > maxSunny)
{
maxSunny = temp->data.getSunnyDayPerMonth();
maxMonth = temp->data.getMonth();
}
temp=temp->next;
}

cout<<"Maximum sunnydays :"<<maxSunny<<" in month: "<<maxMonth<<"\n";
cout<<"Minimum sunnydays :"<<minSunny<<" in month: "<<minMonth<<"\n";

  
}
int main()
{
int n;
string month;
double amntRainPerMonth;
double amntSnowPerMonth;
int sunnyDayPerMonth;

LinkedList<WeatherStats> ll_stats = LinkedList<WeatherStats>();

cout<<"How many month's data do you want to enter: ";
cin>>n;
cout<<"\n\n";

for(int i=0; i<n; i++)
{
WeatherStats temp = WeatherStats();
cout<<"Enter "<<(i+1)<<" data: \n";
cout<<"\nEnter Month: ";
cin>>month;

cout<<"\nEnter amount of rain: ";
cin>>amtRainPerMonth;

cout<<"\nEnter amount of snow: ";
cin>>amtSnowPerMonth;

cout<<"\nEnter amount of sunnyDays: ";
cin>>sunnyDaysPerMonth;

temp.setMonth(month);
temp.setAmntRainPerMonth(amtRainPerMonth);
temp.setAmntSnowPerMonth(amtSnowPerMonth);
temp.setSunnyDayPerMonth(sunnyDaysPerMonth);

ll_stats.insert(temp);

cout<<"\n\n";
}

print(ll_stats);
calculate(ll_stats);

return 0;
}


Related Solutions

Note: I need a code and other requirement Note: programming language is c++ If you need...
Note: I need a code and other requirement Note: programming language is c++ If you need more information, please clarify what information you want. consider solving the equation sin(x) - e^(-x) = 0 write a computer program to solve the given equation using: 1- bisection method 2- fixed-point method 3- newton's intervals: {0,1},{1,2},{2,3},{3,4},{4,5},{5,6},{6,7},{7,8},{8,9},{9,10} choose accuracy E = 10^(-5) Make sure you document your program Requirement : 1- Mathematical justification 2- algorithem description 3- code (program) with documentation 4-output: roots ,...
C++ Programming-Need getGrades function (I keep getting errors). Write a function called getGrades that does the...
C++ Programming-Need getGrades function (I keep getting errors). Write a function called getGrades that does the following: Take an array of integers and an integer representing the size of the array as parameters. Prompt the user to enter up to 20 grades. Store the grades in the array. Return the number of grades entered. Write another function called calcStats that does the following: Take an array of integers and an integer representing the size of the array as normal parameters....
C++: (I need this program to output in a certain format I will post the "needed...
C++: (I need this program to output in a certain format I will post the "needed results" below) To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies might use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letter. Write a program...
I am building a game in C programming language where I need to add objects of...
I am building a game in C programming language where I need to add objects of various length into a game board. The game board is 8X8 and we must account for the boundaries for the board and not go over them with our objects. The boards upper left corner is at 0x0 and we must return 1 if it fits and -1 if it does not fit. I have the following 2 functions to start with: ```int add_object_vert(int r,...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
if I need to get the sum of 6 numbers, here is a C programming solution...
if I need to get the sum of 6 numbers, here is a C programming solution int getSum(int number1, int number2, int number3, int number4, int number5, int number6); and the function is: int SUM; sum = number1+number2+number3+number4+number5+number6; return SUM; this function is called in main, and the main looks like: int totalSum; totalSum=getSum(1,2,3,4,5,6); while(1); so how can I write this C programming code in ARM assembly code, can you please write the comment of each line so I can...
Programming in C (not C++) ## Requirements Only need to edit the challenge.c You have one...
Programming in C (not C++) ## Requirements Only need to edit the challenge.c You have one function to implement: void fork_exec(char** argv): This takes in an array of strings representing arguments. The first argument is the filename of an executable (which will be given as a relative filepath, such as "./a") The remaining terms would be arguments for said executable. The array is null terminated You need to fork your process. The child needs to call exec (rather, a variant...
I have to translate C++ code into MIPS. It is expected to have an output of:...
I have to translate C++ code into MIPS. It is expected to have an output of: Value of a: 25 Value of b: 31 Value of c: 18 Value of d: 49 Here is the C++ code: I need to translate this C++ into MIPS code. #include using namespace std; int main(void) { int a = 5; int b = 6; int c = 7; int d; d = -1; if ( a < 10){ a++; }else{ a--; } d...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting)...
I need this in C# please. Exercise #2: Design and implement a programming (name it NextMeeting) to determine the day of your next meeting from today. The program reads from the user an integer value representing today’s day (assume 0 for Sunday, 1 for Monday, 2 for Tuesday, 3 for Wednesday, etc…) and another integer value representing the number of days to the meeting day. The program determines and prints out the meeting day. Format the outputs following the sample...
Using C programming I have a file that contains earthquake data that I will copy and...
Using C programming I have a file that contains earthquake data that I will copy and paste below. I want to use either bubble or insertion sort to sort the file by latitude in ascending order, then create a new file containing the sorted data. example file to sort: time,latitude,longitude,depth,mag,magType,nst,gap,dmin,rms,net 2020-10-17T17:22:03.840Z,32.877,-116.2991667,0.31,1.16,ml,21,119,0.07747,0.26,ci 2020-10-17T17:17:29.980Z,34.1611667,-116.452,2.75,0.87,ml,17,66,0.05224,0.22,ci 2020-10-17T17:03:54.460Z,33.5396667,-116.4613333,8.66,0.63,ml,18,126,0.06084,0.16,ci 2020-10-17T16:55:01.080Z,63.254,-151.5232,8,1.4,ml,,,,0.9,ak
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT