# Pseudocode Explanation Needed

Discussion in 'C++' started by scojikl, Aug 28, 2007.

1. ### scojiklNew Member

Joined:
Aug 28, 2007
Messages:
2
0
Trophy Points:
0
Hi,

Please look at the below pseudocode and help me understand in as much detail as possible why the value of variable A would be 32. Thanks.

SET A TO 1
SET B TO 3
SET A TO A + B
WHILE A < 20
SET A TO (A*A)/2
END WHILE

2. ### jwshepherdNew Member

Joined:
Aug 13, 2007
Messages:
135
0
Trophy Points:
0
Occupation:
VP Technology Corporation
Location:
Texas
a=4
set a=(4*4)/2
a=8
a < 20 true do loop again
set a = (8*8)/2
a=32

3. ### scojiklNew Member

Joined:
Aug 28, 2007
Messages:
2
0
Trophy Points:
0

4. ### jwshepherdNew Member

Joined:
Aug 13, 2007
Messages:
135
0
Trophy Points:
0
Occupation:
VP Technology Corporation
Location:
Texas
no problem. Good Luck

5. ### DaWeiNew Member

Joined:
Dec 6, 2006
Messages:
835
5
Trophy Points:
0
Occupation:
Semi-retired EE
Location:
Texan now in Central NY
Consider working through such things step by step, with pencil and paper. Microprocessors are not magic. They do precisely what is asked of them.

6. ### yutalolapNew Member

Joined:
Mar 1, 2010
Messages:
1
0
Trophy Points:
0
Code:
```#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class sll
{
private:
typedef struct node
{
int data;
struct node *next;
}s1;
int length;
public:
sll();
void create();
void display();
void search();
void del();
void sort();
};
sll::sll()
{
}
void sll::create()
{
s1 *temp,*new1;
int num,a,i;
cout<<"\nEnter the number of nodes to be created\n";
cin>>num;
for(i=0;i<num;i++)
{
new1=new s1;
cout<<"Enter data:\t";
cin>>a;
new1->data=a;
new1->next=NULL;
temp->next=new1;
temp=new1;
}
}
void sll::display()
{
s1 *temp=NULL;
length=0;
temp=head->next; //To access the 1st node created
cout<<"\nNode\t\tData\t\tNext\n";
while(temp!=NULL)
{
cout<<"\n"<<temp<<"\t"<<temp->data<<"\t\t"<<temp->next;
temp=temp->next;
length++;
}
cout<<"\nTotal number of nodes = "<<length<<endl;

}
void sll::search()
{
s1 *temp=NULL;
int a,flag=0;
cout<<"\nEnter the data you want to search:\t";
cin>>a;
while(temp!=NULL)
{
if(temp->data==a)
{
flag=1;
break;
}
else
{
temp=temp->next;
}
}
if(flag==1)
{
}
else
{
}
}
void sll::del()
{
s1 *temp,*pre;
int a,flag=0;
cout<<"Enter the element you want to delete:\t";
cin>>a;
while(temp!=NULL)
{
if(temp->data==a)
{
flag=1;
pre->next=temp->next;
delete temp;
break;
}
else
{
pre=temp;
temp=temp->next;
}
}
if(flag==1)
{
cout<<"\nData successfully deleted"<<endl;
}
else
{
}
}

{
s1 *temp=NULL,*new1=NULL;
int a,pos,i;
cout<<"Enter the element you want to add:\t";
cin>>a;
cout<<"\nEnter position where you want to add the data:\n";
cin>>pos;
new1=new s1;
if(pos==1)
{
new1->data=a;
}
else
{
for(i=0;i<pos-2;i++)
{
if(temp==NULL)
{
cout<<"Improper position"<<endl;
break;
}
else
{
temp=temp->next;
}
}
new1->data=a;
new1->next=temp->next;
temp->next=new1;
}

}

void sll::sort()
{
s1 *temp,*temp1;
int a,i,j;
for(i=0;i<length-1;i++)
{
temp1=temp->next;
for(j=0;j<length-1;j++)
{
if(temp->data>temp1->data)
{
a=temp->data;
temp->data=temp1->data;
temp1->data=a;
}
temp=temp->next;
temp1=temp->next;

}
}
cout<<"Data successfully sorted"<<endl;
//	length=0;
}

void main()
{
int ch;
sll s;
clrscr();
while(1)

{
cout<<"\nYou can perform the following operations:\n";
cout<<"Which operation you would like to perform?\n";
cin>>ch;
switch(ch)
{
case 7:
exit(0);
case 1:
s.create();
break;
case 2:
s.display();
break;
case 5:
s.search();
break;
case 4:
s.del();
break;
case 3:
break;
case 6:
s.sort();
}
}

}
```
i need to rite this entire thing in a pseudo code format... pls can sum one help me! I am not sure about the rules.

Last edited by a moderator: Mar 1, 2010