11-02-2011, 02:06 AM
:'( :'( :'(
|
CS301 Data Structures assignment no 1 spring 25 October 2011
|
|
11-02-2011, 02:06 AM
:'( :'( :'(
11-02-2011, 04:27 AM
#include<iostream.h>
#include<string.h> #include<stdlib.h> #include<ctype.h> class expression { private: char infix[100]; char stack[200]; int first; int r; char postfix[100]; public: void convert(); int input_p(char); int stack_p(char); int rank(char); }; int expression::input_p(char c) { if(c=='+' || c=='-') return 1; else if(c=='*' || c=='/') return 3; else if(c=='^') return 6; else if(isalpha©!=0) return 7; else if(c=='(') return 9; else if(c==')') return 0; else { cout<<"Invalid expression ::input error\n"; exit(0); } } int expression: tack_p(char c){ if(c=='+' || c=='-') return 2; else if(c=='*' || c=='/') return 4; else if(c=='^') return 5; else if(isalpha©!=0) return 8; else if(c=='(') return 0; else { cout<<"Invalid expression : tack error\n";exit(0); } } int expression::rank(char c) { if(c=='+' || c=='-') return -1; else if(c=='*' || c=='/') return -1; else if(c=='^') return -1; else if(isalpha©!=0) return 1; else { cout<<"Invalid expression ::in rank\n"; exit(0); } } void expression::convert() { cout<<"\n*************************************************\n" <<"This program converts the given infix expression\n" <<"in to postfix form" <<"\n*************************************************\n"; cout<<"Enter an infix expression ::\n"; cin>>infix; int l=strlen(infix); infix[l]=')'; infix[l+1]="; //Convertion starts first=1; stack[first]='('; r=0; int x=-1; int i=0; char next=infix[i]; while(next!=") { //Pop all the elements to outputin stack which have higher precedence while( input_p(next) < stack_p(stack[first]) ) { if(first<1) { cout<<"invalid expression : tack error\n";exit(0); } postfix[++x]=stack[first]; first-; r=r+rank(postfix[x]); if(r<1) { cout<<"Invalid expression ::r<1\n"; exit(0); } } if(input_p( next ) != stack_p( stack[first])) stack[++first]=next; else first-; i++; next=infix[i]; } postfix[++x]="; if(r!=1 || first!=0) { cout<<"Invalid expression ::error in rank or stack\n"; exit(0); } cout<<"\n\nThe corresponding postfix expression is ::\n"; cout<<postfix<<endl; } int main() { expression obj; obj.convert(); return 0;
11-02-2011, 04:32 AM
is it compiling and not giving any error?
11-02-2011, 07:38 PM
It is required to make a list of students registered in Data Structures course. To achieve this functionality, develop a C++ program and use linked list to store student ids and names.
[FONT="]Each node in the linked list will contain three items: student id, student name, pointer to next node.[/FONT] [FONT="]When the program starts, it should display the following menu:[/FONT] [FONT="]1- [/FONT][FONT="]Enter student information[/FONT] [FONT="]2- [/FONT][FONT="]Search student by ID[/FONT] [FONT="]3- [/FONT][FONT="]Search student by Name[/FONT] [FONT="]4- [/FONT][FONT="]Delete student information[/FONT] [FONT="]5- [/FONT][FONT="]Print all students[/FONT] [FONT="]6- [/FONT][FONT="]Quit[/FONT] [FONT="]Sample Run:[/FONT] [FONT="]1- [/FONT][FONT="]Enter student information[/FONT] [FONT="]2- [/FONT][FONT="]Search student by ID[/FONT] [FONT="]3- [/FONT][FONT="]Search student by Name[/FONT] [FONT="]4- [/FONT][FONT="]Delete student information[/FONT] [FONT="]5- [/FONT][FONT="]Print all students[/FONT] [FONT="]6- [/FONT][FONT="]Quit[/FONT] [FONT="]Enter your choice: 1 (Suppose user entered 1)[/FONT] [FONT="](Now the details of Student will be entered)[/FONT] [FONT="]Student ID: bc080400001 (Suppose user entered bc080400001)[/FONT] [FONT="]Student Name: Ahmad (Suppose user entered Ahmad)[/FONT] [FONT="](If user enters an ID that is already in the list, a message should be displayed “Already in the list.”)[/FONT] [FONT="](Main menu will be displayed again)[/FONT] [FONT="]1- [/FONT][FONT="]Enter student information[/FONT] [FONT="]2- [/FONT][FONT="]Search student by ID[/FONT] [FONT="]3- [/FONT][FONT="]Search student by Name[/FONT] [FONT="]4- [/FONT][FONT="]Delete student information[/FONT] [FONT="]5- [/FONT][FONT="]Print all students[/FONT] [FONT="]6- [/FONT][FONT="]Quit[/FONT] [FONT="]Enter your choice: 2 (Suppose user entered 2)[/FONT] [FONT="]Student ID: bc080400001 (Suppose user entered bc080400001)[/FONT] [FONT="](Now the details of Student will be displayed)[/FONT] [FONT="]Student ID: bc080400001[/FONT] [FONT="]Student Name: Ahmad[/FONT] [FONT="](If user enters an ID that is not in the list, a message should be displayed “Record not found.”)[/FONT] [FONT="](Main menu will be displayed again)[/FONT] [FONT="]1- [/FONT][FONT="]Enter student information[/FONT] [FONT="]2- [/FONT][FONT="]Search student by ID[/FONT] [FONT="]3- [/FONT][FONT="]Search student by Name[/FONT] [FONT="]4- [/FONT][FONT="]Delete student information[/FONT] [FONT="]5- [/FONT][FONT="]Print all students[/FONT] [FONT="]6- [/FONT][FONT="]Quit[/FONT] [FONT="]Enter your choice: 4 (Suppose user entered 4)[/FONT] [FONT="](Now it will ask to enter ID to be deleted)[/FONT] [FONT="]Student ID: bc080400001 (Suppose user entered bc080400001)[/FONT] [FONT="](Student record with this ID will be deleted.)[/FONT] [FONT="](Main menu will be displayed again)[/FONT] [FONT="]1- [/FONT][FONT="]Enter student information[/FONT] [FONT="]2- [/FONT][FONT="]Search student by ID[/FONT] [FONT="]3- [/FONT][FONT="]Search student by Name[/FONT] [FONT="]4- [/FONT][FONT="]Delete student information[/FONT] [FONT="]5- [/FONT][FONT="]Print all students[/FONT] [FONT="]6- [/FONT][FONT="]Quit[/FONT] [FONT="]Enter your choice: 5 (Suppose user entered 5)[/FONT] [FONT="](Now it will print all students’ information. Suppose there were three students in the list, so it will print: )[/FONT] [FONT="]Student ID Student Name[/FONT] [FONT="]------------- ---------------------[/FONT] [FONT="]bc080400001 Ahmad[/FONT] [FONT="]bc080200010 Ali[/FONT] [FONT="]mc070400002 Hassan[/FONT]
11-02-2011, 08:04 PM
yah dubara post ker di
11-03-2011, 04:56 PM
Code: #ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include
using name space std;
template span>class T>
class LList
{
Private:
class ListNode
{
friend class LList;
T value;
ListNode *nest;
ListNode(T value1, ListNode *next1=NULL)
{
value=value1;
next=next;
}
};
ListNode *head;
public:
LList()
{
head=NULL;
)
~LList();
void appendNode(T);
void insertNode(T);
void deleteNode();
voide displayList();
void MoveNext();
void ShowCurrent();
};
template
voidLList::appendNode(T val)
{
if(head=NULL)
head=new ListNode(val);
else
{
ListNode *nodePtr;
while (nodePtr->next !=NULL)
nodePtr->next=new ListNode(val);
}
}
template
voidLList::displayList()
{
ListNode *nodePtr;
nodePtr =head;
while (nodePtr)
{
cout nodePtr->value endl;
nodePtr =nodePtr->next;
}
}
template
voidLList::ShowCurrent()
{
ListNode *nodePtr;
nodePtr=head;
countnodePtr->value endl;
}
template
voidLList::MoveNext()
{
ListNode *nodePtr;
nodePtr=head;
while (nodePtr)
{
nodePtr = nodePtr->next;
}
}
template
voidLList::insertNode(T val)
{
ListNode *nodePtr, *previousNodePtr;
if(head==NULL || head->value>=val)
{
head=new ListNode(val, head);
}
else
{
previousNodePtr=head;
nodePtr = head->next;
while (nodePtr !=Null&&nodePtr->value
{
previousNodePtr=NodePtr;
nodePtr = nodePtr->next;
previousNodePtr->nest=new ListNode(val, nodePtr);
template
voidLList::deleteNode()
{
ListNode *nodePtr, *previousNodePtr;
if(!head)
return
nodePtr=head;
head=head->next;
deletenodePtr;
}
template
LList::~LList
()
{
ListNode *nodePtr, *nextNodePtr;
nodePtr=head;
while (nodePtr !=NULL)
{
nextNodePte=nodePtr->nest;
delete nodePtr;
nodePtr=nextNodePtr;
}
}
#endif
Source of Mail Program
#include
#include
#include
#include "LList.h"
int main()
{
int TotalPersons=0,NumberofPasses,
LoopCounter=0,a=0,b=0;
string NameToAppend
count"how many people will play parates of Carribeans : course of black pearl game?
";
cin>>TotalPersons;
count"how many passes will be displayed? ";
cin>>NumberofPasses;
LListlist;
while(LoopCounter <=TotalPersons)
{
count"enter players name: ";
cin>>NameToAppend
list.appendNode(nameToAppend);
LoopCounter +=1;
}
while(a<=TotalPersons-1)
{
for(int c=0;c<=NumberodPasses;c++)
{
list.MoveNext();
}
count"removing :";
list.deleteNode();
list.ShowCurrent();
a+=1;
}
count"\nthe survivor is";
list.displayList();
getch();0300-9520262 Get solution in 24 hour |cpmputer & internet mileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
11-10-2011, 03:10 AM
AOA
bhai ye kia solution ha!! if u want to help someone then help him/her complete! thanks anyway.....
11-10-2011, 04:41 AM
janab thake hi tu hai. ab baki compile tu khud kar len na.
|
|
« Next Oldest | Next Newest »
|