Forum Replies Created
- AuthorPosts
- GWILouisaxwzklaParticipant
You could do this if you choose to write everything from scratch ( you will need to write your own input / output functions in assembly language for DOS I’m not sure if you can do this for Windows , though ). I’ll see if I can write an example latter…..
GWILouisaxwzklaParticipantFor an R-value violation you could do this:
12345678910<br />void func ( int i );<br /><br />int main()<br />{<br />int i = func ( 3 );<br /><br />}<br /><br />pretty sure that would constitute a R-value violation…….
GWILouisaxwzklaParticipantAn L-value violation is easy , just put a constant on the left hand side of an equation:
1234567<br />const int myInt = 9;<br /><br />..<br />myInt = 3; // need an L-value here<br /><br />You need something that is assignable for a L-value. R-value violations are tougher , I’ll have to look into this…….
GWILouisaxwzklaParticipantCould you post your data file?
GWILouisaxwzklaParticipantHeres a postfix to infix program I have on my drive ( hope this helps….. ):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264#include < conio.h ><br />#include < math.h ><br />#include < string.h ><br />#include < stdlib.h ><br />#include < stdio.h ><br /><br />enum Boolean { False = 0 , True = 1 } ;<br />const int GREATER = 1 ;<br />const int NOTGREATER = 0 ;<br />int cnt = 0 , cntcol = 0 , postcnt = 0 ;<br /><br />//<hr class="bbcode_rule" />struct Stack<br />{<br />int info ;<br />Stack * previous;<br />} * top;<br /><br />//<hr class="bbcode_rule" />void Push ( int number )<br />{<br />Stack * current;<br />current = new ( Stack ) ;<br />if ( current == 0 )<br />{<br />printf ( "n allocation error!!!!! " );<br />return;<br />}<br />current -> info = number ;<br />current -> previous = top ;<br />top = current ;<br />}<br /><br />//<hr class="bbcode_rule" />int Pop ()<br />{<br />int temp ;<br />Stack * current = top;<br />temp = current -> info ;<br />top = top -> previous ;<br />delete current ;<br />return temp ;<br />}<br /><br />//<hr class="bbcode_rule" />int StackTop ()<br />{<br />return top -> info ;<br />}<br /><br />//<hr class="bbcode_rule" />Boolean isEmpty()<br />{<br />if ( top == NULL )<br />return True;<br />else<br />return False ;<br />}<br /><br />//<hr class="bbcode_rule" />Boolean isOperand ( char ch )<br />{<br />if ( ch >= '0' && ch <= '9' ) //if is a number<br />return True;<br />else<br />return False ;<br />}<br /><br />//<hr class="bbcode_rule" />void Infix ( char infix[][10])<br />{<br />char c ;<br />while ( c != 13 )<br />{<br />c = getch() ;<br />putch(c);<br />if ( c >= '0' && c <= '9' )<br />{<br />infix [cnt][cntcol] = c ;<br />cntcol++ ;<br />}<br />else if ( c == '+'|| c == '-'|| c == '*'|| c == '/')<br />{<br />infix [cnt][cntcol] = ' ' ;<br />cnt++ ;<br />infix [cnt][0] = c ;<br />infix [cnt][1] = ' ' ;<br />cnt++ ;<br />cntcol = 0 ;<br />}<br />else if ( c == 13 )<br />infix[cnt][cntcol] = ' ' ;<br />}<br />}<br /><br /><br />//<hr class="bbcode_rule" />int Calculate (int op1, char opr, int op2)<br />{<br />int ans ;<br />switch ( opr )<br />{<br />case '+' : ans = op1 + op2 ; break ;<br />case '-' : ans = op1 - op2 ; break ;<br />case '*' : ans = op1 * op2 ; break ;<br />case '/' : ans = op1 / op2 ; break ;<br />case '^' : ans = pow(op1, op2) ;<br />}<br />return ans ;<br />}<br />//<hr class="bbcode_rule" />int Evaluate ( char postfix[][10] )<br />{<br />for ( int i = 0 ; i <= cnt ; i ++ )<br />{<br />char ch = postfix<i>[0] ;<br />char ch1[10] ;<br />strcpy ( ch1 ,postfix </i><i> ) ;<br />// cout <<endl<< atoi ( ch1) ;<br />if ( isOperand ( ch ) == True )<br />Push ( atoi(ch1) );<br />else<br />{<br />int op2 = Pop () ;<br />int op1 = Pop () ;<br />int ans = Calculate ( op1, ch, op2 ) ;<br />// cout << ans << endl ;<br />Push ( ans ) ;<br />}<br />}<br />int ans = Pop () ;<br />return ans ;<br />}<br /><br />// </i><hr class="bbcode_rule" />int CheckP (char cur, char st)<br />{<br />int a = NOTGREATER ;<br /><br />if ( cur == '(' )<br />a = GREATER ;<br />else if ( cur != '(' && st == '(' )<br />a = GREATER ;<br />else if ( cur != '(' && st != '(' )<br />{<br />if ( ( cur == '*' || cur == '/' ) && ( st == '+' || st == '-' ) )<br />a = GREATER ;<br />}<br />return a ;<br /><br />}<br /><br /><br />//<hr class="bbcode_rule" />void infixToPostfix ( char infix[][10], char postfix[][10] )<br />{<br />int postcol = 0 ;<br />for ( int i = 0 ; i <= cnt ; i ++ )<br />{<br />// strcpy(postfix<i>, infix </i><i>) ;<br />// cout << postfix</i><i> ;<br />char ch;<br />ch = infix</i><i>[0] ;<br />if ( isOperand ( ch ) == True )<br />strcpy ( postfix [postcnt++] , infix </i><i> ) ;<br />else<br />{<br />if ( isEmpty() == True )<br />Push ( int(ch) ) ;<br />else<br />{<br />while ( CheckP( ch, StackTop() ) != GREATER && isEmpty() != True )<br />{<br />char c ;<br />if ( ch == ')' )<br />{<br />do<br />{<br />c = char ( Pop() ) ;<br />if ( c != '(')<br />{<br />postfix [postcnt][postcol] = c ;<br />postfix [postcnt][postcol+1] = ' ' ;<br />postcnt++ ;<br />}<br />}while ( c != '(' && isEmpty() != True);<br />break ;<br />}<br />else<br />c = char ( Pop() ) ;<br />if ( c != '(' && c != ')' )<br />{<br />postfix [postcnt][postcol] = c ;<br />postfix [postcnt][postcol+1] = ' ' ;<br />postcnt++ ;<br />}<br />}<br />if ( ch != ')' )<br />Push ( int(ch) ) ;<br />}<br />}<br />}<br /><br />while ( isEmpty () != True )<br />{<br />char c = char ( Pop () ) ;<br />postfix [postcnt][postcol] = c ;<br />postfix [postcnt][postcol+1] = ' ';<br />postcnt++ ;<br />}<br />// postfix[postcnt][postcol] = ' ';<br />}<br /><br />//</i><hr class="bbcode_rule" />void Postfix ( char postfix[][10] )<br />{<br />char ch[10] ;<br />for ( int i = 0; i <= postcnt; i++ )<br />{<br />strcpy(ch , postfix<i> ) ;<br />printf ( "%c" ,ch );<br />}<br />}<br /><br />// </i><hr class="bbcode_rule" />void main()<br />{<br />//clrscr();<br />top = NULL ;<br /><br />char infix [ 50 ][ 10 ] ;<br />char postfix [ 50 ][ 10 ] ;<br /><br />//gotoxy ( 5, 8 ) ;<br />printf ( "Enter Arithematic Expression ...................... : " );<br />Infix ( infix ) ;<br /><br />infixToPostfix ( infix, postfix ) ;<br />//gotoxy ( 5, 10 ) ;<br />printf ( "Arithematic Expression in Postfix Notation......... : " );<br />Postfix ( postfix ) ;<br />int ans = Evaluate ( postfix ) ;<br />//gotoxy (5, 11 ) ;<br />printf ( "The Answer of Expression .......................... : " );<br />printf ( "%i", ans );<br /><br />getch();<br />}<br />//<hr class="bbcode_rule" />GWILouisaxwzklaParticipantCould do this:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : February 21 , 2010<br />* Comments : new project<br />* Compiler/Assembler : Visual C++ 6.0<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 1:00:53 a.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br />using namespace std;<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />char ch;<br />int i;<br />char newline = 10;<br />float decimalEquivalent = 0;<br />float multiplier = .5;<br /><br />cout << "enter a binary fraction: " ;<br /><br />ch = cin.get(); //get decimal point<br />ch = cin.get() ; //get first digit of number<br /><br />while ( ch != newline ) //while not at the end of input<br />{<br />decimalEquivalent = decimalEquivalent + ( ch - '0' ) * multiplier;<br />multiplier = multiplier * .5;<br />ch = cin.get() ; // get next digit<br />}<br /><br />cout << endl << endl;<br />cout << "decimal equivalent is : " << decimalEquivalent << endl;<br />}<br /><br /><br /><br /><br />GWILouisaxwzklaParticipantUnless theres a new C++ standard , you cannot declare arrays of an arbitrary length ( the length must be declared as a constant so the compiler knows how to set up the function’s stack frame at compile time ). So you can’t do this ( I’m suprised this compiled, what compiler are you using ?):
123<br />int array [ g + 1 ];<br />If you want a arbitrary length array you have to allocate it at run time , like:
123<br />int * array = new int [ g + 1 ];<br />make sure to check allocation of this statement and delete the memory when your done with it ( by the end of the function call )………
February 21, 2010 at 9:43 pm in reply to: clrscr(), window(), textcolor() etc. not in conio.h? #3635GWILouisaxwzklaParticipantTheres a seperate debugging utility called “turbo debugger” or something. Its a small DOS box utility that debugs object files made with Turbo C++ , as I remember. Heres a link to some info on this http://www.winprog.org/tutorial/bcpp.html
February 18, 2010 at 7:16 pm in reply to: clrscr(), window(), textcolor() etc. not in conio.h? #3633GWILouisaxwzklaParticipantI haven’t used this compiler for a looong time , but as I remember you have to do a few small things to configure it or it will not work properly. Heres a link that shows how to configure it http://edn.embarcadero.com/article/21205 , you can also google set up Borland command line tools .
February 17, 2010 at 9:06 pm in reply to: clrscr(), window(), textcolor() etc. not in conio.h? #3631GWILouisaxwzklaParticipantThe functions clrscr(), ect. are exclusive to the Borland Turbo Compiler. I think the easiest way to compile the code would be to download the free Borland Command Line Tools Package ( I think you can find it here: http://edn.embarcadero.com/article/20633 ) or just google free Borland Command Line Tools Package download. You could also write your own replacement functions and add them to the one of the VC++ library ( could code these using Windows API calls for 32-bit Windows applications ).
GWILouisaxwzklaParticipantCould you perhaps post the input file for your program?
GWILouisaxwzklaParticipantWhat does your input file look like? What criteria is used to select samples ( randomly ).
GWILouisaxwzklaParticipantNot sure what your doing. Does this relate to linked lists?
GWILouisaxwzklaParticipantHeres a simple version ( the items are entered into the list from the back )
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106<br />/****************************************************************<br />* File Name : c:programstempCG.cpp<br />* Date : January,8,2010<br />* Comments : new project<br />* Compiler/Assembler : Visual C++ 6.0<br />* Modifications :<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 4:13:24 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br /><br />using namespace std;<br /><br />//node for the list<br />struct node<br />{<br />int data;<br />node * next;<br />};<br /><br /><br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />cout << "enter numbers ( 0 to stop ) " << endl << endl;<br /><br />node * front = NULL; //front of the linked list<br />node * temp = NULL;<br />node * back = NULL;<br /><br />int input;<br /><br />cout << "enter number: ";<br />cin >> input;<br /><br />//######### READ THE LIST FROM THE KEYBOARD<br /><br />while ( input != 0 )<br />{<br />temp = new node; //make a new node in the list<br />if ( temp == NULL ) //check that node was allocated properly<br />{<br />cout << "allocation error , node not stored! " << endl;<br />continue;<br />}<br />temp -> data = input;//copy data<br />temp -> next = NULL; //new item has no next item<br />if ( front == NULL ) //if the list is empty add a new node<br />{<br />front = temp; //front of list points to temp<br />back = temp; //back of list pointer points to temp<br />}<br />else //add the item to the back of the list<br />{<br />back -> next = temp;//next item in the list is the item read<br />back = temp; //new item is the new last item<br />}<br />cout << "enter number: "; //get the next number<br />cin >> input;<br />}<br /><br /><br />cout << "Printed list: " << endl << endl;<br /><br />temp = front; //start at the front of the list<br /><br />//############ PRINT THE LIST<br /><br />while ( temp ) //while not at the end of the list<br />{<br />cout << temp -> data << " " ; //output data in list item<br />temp = temp -> next; //go to next item in the list<br />}<br /><br />//######## DELETE THE LIST<br /><br />while ( front )<br />{<br />temp = front; //save the address of the front node<br />front = front -> next; //make the next item first<br />delete temp; //deallocate memory for the old front node<br />}<br /><br /><br />return 0 ;<br />}<br /><br /><br /><br /><br />GWILouisaxwzklaParticipantcould try:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303<br />/****************************************************************<br />* File Name : cgt.cpp<br />* Date : April,10,2007<br />* Comments : new project<br />* Compiler/Assembler : VC++ 6.0<br />*<br />*<br />*<br />*<br />*<br />* Program Shell Generated At: 2:59:58<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br /><br />#include < iostream ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br /><br />using namespace std;<br /><br />struct node<br />{<br /><br />int data;<br />node * next;<br />node * back;<br /><br />};<br /><br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br /><br />void readList ( node ** list );<br />bool listsAreEqual ( node * left , node * right );<br />node * copyList ( node * list );<br />void printList ( node * list );<br />void destroyList ( node ** list );<br />bool listsContainEqualMembers ( node * left , node * right );<br /><br />//##################################################################################<br /><br />//main function ******************************<br /><br />int main ( )<br />{<br /><br />node * head1 = 0;<br />node * head2 = 0;<br /><br />cout << "enter first list :" << endl;<br />readList ( & head1 );<br />cout << "enter second list: " << endl;<br />readList ( & head2 );<br /><br />if ( listsAreEqual ( head1 , head2 ) )<br />cout << endl << "The lists are equal" << endl;<br />else<br />cout << endl << "The lists are not equal" << endl;<br /><br />cout << endl;<br />if ( listsContainEqualMembers ( head1 , head2 ) )<br />cout << endl << "lists contain equal members" << endl;<br />else<br />cout << endl << "lists do not contain equal members " << endl;<br /><br /><br />node * copy = copyList ( head1 );<br />cout << endl << "copy of first list is: ";<br />printList ( copy );<br />destroyList ( & head1 );<br />destroyList ( & head2 );<br />destroyList ( & copy );<br />return 0 ;<br />}<br /><br /><br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : readList<br />Parameters :<br /><br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void readList ( node ** list )<br />{<br /><br />cout << "enter an integer ( -1 to stop ) ";<br />int i;<br />cin >> i;<br />node * temp = 0;<br /><br />while ( i != -1 )<br />{<br /><br />temp = new node;<br />if ( temp == 0 )<br />{<br />cout << " allocation error" ;<br />( * list ) = 0;<br />return;<br />}<br />temp -> data = i ;<br />if ( ( * list ) == 0 )<br />{<br />( * list ) = temp;<br />temp -> next = 0;<br />temp -> back = temp;<br /><br />}<br />else<br />{<br />( * list ) -> back -> next = temp;<br />temp -> next = temp -> back = 0;<br />( * list ) -> back = temp;<br />}<br />cout << "enter a number ( -1 to stop ) ";<br />cin >> i;<br />}<br /><br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : listsAreEqual<br />Parameters :<br /><br /><br /><br />Returns: user defined type , bool<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool listsAreEqual ( node * left , node * right )<br />{<br /><br />bool matches = true;<br /><br />while ( left != 0 && right != 0 && matches )<br />{<br /><br />if ( left -> data != right -> data )<br />matches = false;<br />else<br />{<br />left = left -> next;<br />right = right -> next;<br />}<br />}<br />if ( ! left && ! right && matches )<br />return true;<br /><br />return false;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : copyList<br />Parameters :<br /><br /><br /><br />Returns: user defined type , node *<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />node * copyList ( node * list )<br />{<br /><br />node * temp = 0;<br />node * newList = 0;<br /><br />while ( list )<br />{<br /><br />temp = new node;<br />if ( ! temp )<br />{<br />cout << "allocation error! ";<br />return 0;<br />}<br />if ( newList == 0 )<br />{<br />newList = temp;<br />temp -> data = list -> data;<br />newList -> next = 0;<br />newList -> back = temp;<br />}<br />else<br />{<br />temp -> data = list -> data;<br />newList -> back -> next = temp;<br />newList -> back = temp;<br />temp -> next = temp -> next = 0;<br />}<br />list = list -> next;<br />}<br />return newList;<br />}<br />void printList ( node * temp )<br />{<br /><br /><br />cout << "list read is " ;<br />while ( temp )<br />{<br />cout << temp -> data << " ";<br />temp = temp -> next;<br />}<br />cout << endl;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : destroyList<br />Parameters :<br /><br /><br /><br />Returns: user defined type , void<br /><br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void destroyList ( node ** list )<br />{<br /><br /><br />node * temp = ( * list );<br />node * temp2 = 0;<br />while ( temp )<br />{<br /><br />temp2 = temp;<br />temp = temp -> next;<br />delete temp2;<br />}<br /><br />( * list ) = 0;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br /><br />Name : listsContainEqualMembers<br />Parameters :<br /><br /><br /><br />Returns: Void type<br />Comments:<br /><br /><br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool listsContainEqualMembers ( node * left , node * right )<br />{<br /><br /><br />node * temp1 = left;<br />node * temp2 = right;<br />bool matches ;<br />int length1 = 0 , length2 = 0;<br />int numItems1 = 0 , numItems2 = 0;<br /><br />while ( temp1 && matches )<br />{<br />temp2 = right;<br />matches = false;<br />length1 ++; //get length of first list<br />while ( temp2 && ! matches )<br />{<br />if ( temp1 -> data == temp2 -> data )<br />matches = true;<br />if ( ! matches )<br />temp2 = temp2 -> next;<br />}<br />if ( matches )<br />temp1 = temp1 -> next;<br />}<br />temp2 = right;<br />while ( temp2 )<br />{<br />length2 ++ ;<br />temp2 = temp2 -> next;<br />}<br />if ( length1 == length2 && matches )<br />return true;<br />return false;<br />}<br /><br /> - AuthorPosts