Hi, I'm new here and relatively new to c++ as well. I'm trying to write a function which will solve a quadratic equation. The progran needs to distinguish which coefficient is a, b and c. The quadratic is on the command line at argv[2].
So I decided to split the string (quadratic) up to the x
e.g. 4x^2 + 3x + 5
I want the code to read up to x^2 and place the value into a vector. It will then ignore everything until the +/- and then read the value until the x and place that into a vector; once again ignore everything until it passes the +/- and then read the c constant and place that into a vector.
I would prefer to use an array to store the a, b and c values. Can anyone help me with a code to run through the string and extract the required values?
Another issue is this:
Provided i can use an array, can i initialize the array as follows:
arr[0] = a
arr[1] = b
arr[2] = c
where a, b and c can take any values as specified by the user?
Any help would be greatly appreciated.
2 1202 Laharl 849
Recognized Expert Contributor
Vectors would be a mistake, because if a is a multidigit number, the code to transfer from the vector to an integer is more complex than to transfer from a string to an integer.
You can use the strtok() C-string function to split up the input string. The code for this is kind of complicated, but there are good sites (cplusplus.com is the one I usually use) that explain it pretty well with examples.
You could make a copy of the string and start a loop looking at copy[0]. Maje a decision on what it is and what to do with then erase copy[0]. The rest of the string will slide to the left so on the next cycle of your loop copy[0] will be the 2nd character of the origingal string. The loop continues until you have erases the entire copy.
You might look up finite-state automaton, which is the mechanism used for this sort of thing.
Yes, you can use an array to hold your coefficients. Just be aware that the type of the coefficients must match the element type of the array.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Torsten Mohr |
last post by:
Hi,
i'd like to pass a reference or a pointer to an object
to a function. The function should then change the
object and the changes should be visible in the calling
function.
In perl this would be something like:
sub func {
|
by: Mike |
last post by:
Hey guys I am pulling my hair out on this problem!!!!! Any help or ideas or
comments on how to make this work I would be grateful! I have been working
on this for the past 4 days and nothing I do seems to get me any closer to
the solution. Below is a program that I am working on for a class project.
The original code was provided for us which is what I have below. What we
have to do is make the app run so that it allows the user to add...
|
by: Michael B. |
last post by:
I was just thinking about this, specifically wondering if there's any
features that the C specification currently lacks, and which may be
included in some future standardization.
Of course, I speak only of features in the spirit of C; something like
object-orientation, though a nice feature, does not belong in C.
Something like being able to #define a #define would be very handy,
though, e.g:
#define DECLARE_FOO(bar) #define...
|
by: Worker |
last post by:
Hi , i`ve been wondering how many days do you guys need to read an average
asp.net programming book, answer honestly please, for example 800 pages big,
how many pages a day? I just wanna see if i m reading too slow... :)
Next question, i have a simple function from my latest book here and the
authors of "Wrox Beginning Asp.net with c#" were not to eager to explain the
meanings of the theory of code they used in their example so i...
|
by: Justin Weinberg |
last post by:
My thoughts on this....
http://msdn.microsoft.com/vbasic/Future/default.aspx?pull=/library/en-us/dnvs05/html/vb9overview.asp
My thoughts:
1. Regarding Implicit types, I don't use type declaration for the benefits
of performance. It's for the benefit of clarity of purpose when reading
code. The first thing I do with neophyte developers is turn Option Strict
| |
by: Xah Lee |
last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully
Functional Notations
Xah Lee, 2006-03-15
Let me summarize: The LISP notation, is a functional notation, and is
not a so-called pre-fix notation or algebraic notation.
Algebraic notations have the concept of operators, meaning, symbols
placed around arguments. In algebraic in-fix notation, different
|
by: Xah Lee |
last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully
Functional Notations
Xah Lee, 2006-03-15
In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”.
Likewise, they write “(if test this that)” to mean “if (test) {this}
else {that}”. LISP codes are all of the form “(a b c ...)”, where the
|
by: =?Utf-8?B?cm9kY2hhcg==?= |
last post by:
hey all,
what's the best way to turn my csv string into sql parms? the sql parms can
vary in count.
thanks,
rodchar
|
by: sonuindia88 |
last post by:
I am preparing c for entrance examinations..I am reading Ritchie and Deitel and practising questions from Yashwant Kanetkar...Here are some of the confusions i am having..your help is required....
Q1)
#include<stdio.h>
int main()
{
printf("%d \n",-5%-4);
printf("%d\n",-5%4);
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |