How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
How do you stop infinite loop Because I believe that it is making a.pdf
1. How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
2. * The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
3. /**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
4. }
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that's in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
5. * Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that's at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
6. }
/**
* Accessor to return the data of the element at the front of the list.
* Causes an assertion error if the list is empty.
* @return the data in the front element
*/
const Object & front() const
{
assert( !is_empty() );
return first->data;
}
/**
* Accessor to return the data of the element at the tail of the list.
* Causes an assertion error if the list is empty.
* @return the data in the last element
*/
const Object & tail() const
{
assert (!is_empty());
return last->data;
// you implement this method
}
/**
* Accessor to determine whether the list is empty
* @return a boolean corresponding to the emptiness of the list
*/
bool is_empty() const
{
/* you complete this method */
return size == 0;
}
/**
* Generate a string representation of the list
* Requires operator<< to be defined for the list's object type
* @return string representation of the list
*/
7. string to_string() const
{
if( size == 0 )
{
return "";
}
stringstream buffer;
for( auto current = first; current != nullptr; current = current->next )
{
buffer << current->data << ' ';
}
return move( buffer.str() );
}
private:
uint size;
Node * first;
Node * last;
int count;
};
#endif
here is the test class:
#include
#include
#include
#include "lin_j_list.h"
using namespace std;
typedef unsigned int uint;
int main( int argc, char * argv [] )
{
if( argc != 2 )
{
cerr << "Usage: " << argv[0] << " n where n is the number of elements" << endl;
return 1;
}
stringstream ss( argv[ 1 ]); // get the command line parameter
8. uint n = 0;
ss >> n;
srand( time( NULL ));
cout << "starting to create l1 and l2" << endl;
List l1;
List l2;
for( uint i = 0; i < n; i++)
{
uint value = rand() % UINT_MAX;
l1.push_front( value );
l2.push_front( value );
}
cout << "starting to construct l3 from l1" << endl;
List l3{ l1 };
cout << "starting to copy l1 onto l2" << endl;
l2 = l1;
cerr << n << "t" << l2.get_count() << "t" << l3.get_count() << endl;
return 0;
}
Solution
Answer:-
#include
#include
using namespace std;
int main()
{
double g;
double s;
double w;
cout << "Greetings, we will be calculation watts per mile per hour ";
9. cout << "Insert Generator's name capacity in watts ";
cin >> g;
if (g < 300)
{
cout << "Nameplate capacity must be between 300 and 8,000,000 watts. ";
}
else if (g > 8,000,000)
{
cout << "Nameplate capacity must be less than 8,000,000. ";
}
exit(-99);
cout << "Insert today's average daily wind speed ";
cin >> s;
if (s < 0)
{
cout << "Wind speed must be greater than zero. ";
}
else if ((s >= 0) && (s < 6))
{
cout << "Wind speed is not sufficient to power the generator. ";
}
else if ((s >= 39) && (s <= 73))
{
cout << "Tropical storm wind speeds. Wind turbine not operating. ";
}
else if (s > 73)
{
cout << "TIme to buy a new wind turbine. ";
}
}