Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to add a faction float diff() #include using namespace std; struct node { int info; node *next; }; class sll { private: node

I want to add a faction float diff()
#include
using namespace std;
struct node
{
int info;
node *next;
};
class sll
{
private:
node *head;
public:
sll(){head=NULL;}
void AddNode (int);
void Traverse();
int Sum();
};
void sll::AddNode (int val)
{
node *newNode= new node;
newNode->info=val;
newNode->next=head;
head=newNode;
}
void sll::Traverse()
{
if (head==NULL)
cout
for (node * curr=head;curr; curr=curr->next)
coutinfo
}
int sll::Sum ()
{
int sum=0;
for (node * curr=head;curr; curr=curr->next)
sum+=curr->info;
return sum;
}
int main()
{
sll s;
int inf, ch;
while(1)
{
cout
cin>>ch;
switch(ch)
{
case 1:
cout
cin>>inf;
s.AddNode(inf);
break;
case 2:cout
s.Traverse();
break;
case 3:
cout
break;
default: exit(0);
} // end of switch
} // end of while loop
return 0;
}
image text in transcribed
Create a program to store a list of integer numbers dynamically through a singly linked list, your program should contain the following functions: 1- AddNode (int): Adds a new node at the end of the list. 2- Traverse0: Prints the values stored in the list. 3- float diffo: Returns the difference between the average of positive numbers and the average of negative numbers. Note: - Just attach the code for the third function in your answer. - You should also attach a screenshot of the program output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions