473,569 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to input the complete polynomial at once and arrange it's terms in a linked form?

dev7060
639 Recognized Expert Contributor
The program is of addition of the polynomials. Implementing it through linked lists. Every node of the list has three fields: coefficient, exponent and the next pointer field pointing to the next node of the polynomial expression. The next pointer field of the last node contains NULL.

Right now, the coefficients and exponents are to be entered separately by the user. The coefficient and exponent are then added to the list by adding them to node's fields and then adding the node at the end of the expression.

Like:
(Output screen)

Enter coefficient: 5
Enter exponent: 2
Expression now is: 5x^2
Press 1 to continue insertion ...

The code that assigns these values to node's fields and add then to the expression is:

Expand|Select|Wrap|Line Numbers
  1.     node=(struct POLYS *)malloc(sizeof(struct POLYS));
  2.     cout<<"Enter coef: ";
  3.     cin>>node->coef;
  4.     cout<<"Enter exponent:";
  5.     cin>>node->exp;
  6.     node->next=NULL;
  7.     temp1=start;
  8.     if(start==NULL){
  9.         start=node;
  10.         }
  11.     else{
  12.         while(temp1->next!=NULL){
  13.             temp1=temp1->next;
  14.             }
  15.         temp1->next=node;
  16.         }
where:

-*node, *temp1 and *start are the POLYS type pointers
Expand|Select|Wrap|Line Numbers
  1. struct POLYS{
  2.             int coef;
  3.             int exp;
  4.             struct POLYS *next;
  5.         };
-start points to the first node of the expression

The above method works efficiently but is there any way to input the complete expression at once?

Like:
(Output screen)

Enter expression: 3x^4 + 5x^5 + 8x^6

And then the program can automatically arrange them in a linked form?
Maybe treating the input as a string and then separating the coefficient and exponent of each term of the expression and then adding the values to the node's fields?
Jan 14 '18 #1
6 2425
dev7060
639 Recognized Expert Contributor
I can't edit the title. That's "arrange *its terms in a linked form?"
Jan 14 '18 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
You are using cin. While you enter data, your program is not running. Instead your program is suspended while the input system runs. Your program will not resume until you press the enter key.

So if you enter:

1 2 3 4 <enter>

Your program first cin will process 1 (pause on whitespace
...more of your code executes....

You second cin will process the 2 (pause on whitespace)
...more of your code executes...

etc...

Is this what you mean by "linked form"?

So you should be able to enter:

3x^4 + 5x^5 + 8x^6 <enter>

at one time and have the cins process it correctly.
Jan 14 '18 #3
dev7060
639 Recognized Expert Contributor
Thanks for the reply.

By "arranging in a linked form", I meant to create a node and dynamically allocate the memory for it. Just to clear up:

If the user enters: 3x^4 + 5x^5 + 8x^6

- The program can detect the coefficient and exponent of the first term (at first) of the expression.
- Create a node and set its "coef" and "exp" fields same as entered by the user.
- Add the node to the linked list.
- Similarly, the program can detect the coefficient and exponent of the second term of the expression.
- Create a node and set its "coef" and "exp" fields same as entered by the user.
- Add the node to the linked list (i.e. the next pointer field of the first node will point to this node).
etc..
So after this, there will be a linked list having 3 nodes.
_______________ ______________

"1 2 3 4 <enter>

Your program first cin will process 1 (pause on whitespace
...more of your code executes....

You second cin will process the 2 (pause on whitespace)
...more of your code executes...

etc...

So you should be able to enter:

3x^4 + 5x^5 + 8x^6 <enter>

at one time and have the cins process it correctly.
"

Can you provide a code snippet of that for the explanation of the last one? I understand the working of cins in the simple input format like in "1 2 3 4". But in the "3x^4 + 5x^5 + 8x^6" or in any other expression, some changes may be required like: since as the number of terms present in the expression depends on the user, therefore the code has to manually set the number of times cin will perform its action.
Also, the requirement is only of the exponent and the coefficient. So, how to just extract the useful info from the whole input provided by the user like the values 3, 4 and 8, 6 from 3x^4 + 8x^6 with the help of cins?
Jan 14 '18 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Maybe I wasn't explaining clearly.

In the case of:

1 2 3 4 <enter>

Those, in fact could be your coefficients and exponents.

1x^2
3x^4

It just how you interpret what was entered.

cin returns when what it scans, in this case, is not a digit.

So you pick off the 1

Next, you cin.ignore() to bypass the non digit.

You now pick off the 2.


I am assuming the user will enter exactly what is required, in the correct order, for the correct number of elements. If you try o create a flexible general purpose data entry mechanism, you will be coding for a long, long time. cin/cout are just provided by C++ as a starting point. Commercial applications generally don't use them. Nothing in Windows apps use them.

I would provide only what the program needs in the form that it needs it and not do anything fancy.

Since this appears not to be what you want, let me ask why you need this user flexibility?
Jan 15 '18 #5
dev7060
639 Recognized Expert Contributor
Actually, the flexible data entry mechanism may be beneficial in many cases:

-There are several operations like addition, subtraction, multiplication, division etc. which need to be performed with them. Therefore, the program needs debugging and testing again and again. So, entering the coefficients and exponents of multiple polynomials again and again will be time consuming.

-Right now the things are being tested on a terminal but maybe a GUI at a later point. So, I think it's just a standard way of inputting polynomials, integral equations, trigonometric equations etc. as a whole and treat them accordingly unlike the unprofessional way of inputting the components separately. By inputting them as whole, it may be parsed as a string and can be passed to different modules. Say, parsing stuff can be put in a PolyCommand.h class and Poly.h can have the poly manipulation methods and stuff like addition, multiplication etc.
Jan 15 '18 #6
donbock
2,426 Recognized Expert Top Contributor
If your goal is to speed up debugging/testing then I suggest you modify the front-end to obtain the coefficients from a text file. Each test case could be a different line in the file. Once you have confidence the back-end is working, then you can restore the front-end and merely test that the input subsystem works properly.
Jan 18 '18 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2592
by: Keiron Waites | last post by:
I have the following code: <input type="text" name="search" class="search_top"> <a href="" onclick="window.location='search.inc.php'+document..search. value; return false;" class="search_top">go</a> What do I put within to access the value of the input field search so I can access it's value? Thanks,
3
1744
by: Rahul Agarwal | last post by:
Hi In our web page we use a combination of HTML and server side controls and some of them have a custom attribute based on which we need to find and replace the values once the HTML is ready. For e.g. <LABEL DICTCODE="XYZ">Some text</LABEL> At run time just before the complete HTML is sent to the client-side I want to get hold of the...
0
1314
by: weezles | last post by:
hi I'm having trouble with using a linked form instead of a sub form on a 1 to many relationship. Then linked form can be accessed from various other forms. When it opens the linked form, if there are no records the clientID is 0. I tried the following code behind the button to open the linked form: stLinkCriteria = "=" & Me!
2
1968
by: monnomiznogoud | last post by:
Ok, my problem is the following: I have very complicated Access 97 databases that link through ODBC to Sybase databases. Now in some of the forms controls I had queries that used as "where clause" parameters form field values; For example: select foo from bar where a_colmun = !!
3
1381
by: Michiel Rapati-Kekkonen | last post by:
hi, once upon a time I read that the communication with the back end would be faster if one table there was kept open. For that purpose you were supposed to make an otherwise useless table in the back end, link to it and open it when opening the front end, keeping it open until you close the front end. Is this a indeed viable and useful? ...
0
1302
by: colin | last post by:
Hi, I have an IDE style editor based on the WeifenLuo.WinFormsUI.Docking code, wich I must say seems realy good. Im trying to activate drop down menus and such from various special command key such as the windows apps key, and then do something like build up a context menu using reflection and picking items in the chain of windows and...
3
1350
by: gina farrow | last post by:
I have forms that I need four people to look at and be able to put a check on the form that they have seen it once check cannot be unchecked. the form goes to the next person to check it. when it has gone through all the people that checked at the end put all information in table with the outcome of all the checks.You should be able to see who has...
6
2574
by: Alby22 | last post by:
I have a linked table between two databases(A & B). The data is entered by multiple users in to A once all the data is entered I review the data in B and then append that data to my main table in B. I'm essentially using the linked table as a buffer so if there are any entry mistakes they don't go directly into the main table. After the data is...
2
1111
by: rab26 | last post by:
Hi, It has been a while since I have used Access and even then it was basic use. I think I am thus a little in over my head! Some advice would therefore be much appreciated. The data input form for my database is essentially made up of 3 sections: 1) item description 2) where from 3) where going to In order to prevent the main form...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.