C++ :: Convert A String Into Mathematical Calculation And Calculate In Correct Order

May 6, 2013

I want to program an advanced calculator. I'd like to enter some more complex expressions like -17+3*4*(4-sqrt(4) and i want, that mathematical operations are done the correct order, so at first 4-sqrt(4) is calculated, then 3*4*2 and then -17 is subtracted.

Problem 1: Convert a string into a mathematical calculation
Problem 2: Calculate in the correct order

How would I do that (I dont expect perfecly precoded calculators from you, just the way how to do it)

Google search just delivers primitive calculations with entry methods like

Enter first number 1
Enter operator +
Enter second number 2

3

But thats not what i want

View 2 Replies


ADVERTISEMENT

C :: Convert Float To String In Order To Use Strlen Function

Apr 4, 2013

Any really simple way of converting the following float to a string so I can take strlen()?

float a = 53213421;

strlen(a)?

I have looked up solutions but they are either too long or they confuse me.

View 2 Replies View Related

C/C++ :: Using Semaphores On Critical Region - Processes Not In Correct Order

Mar 2, 2014

I'm trying to use semaphores on three different processes so that each process won't enter the critical region at the same time and also go in the order: process 1 -> process 2 -> process 3. However, everytime i run the code the process 3 keeps going before process 2.

Here's my code:

#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>

[Code].....

the processes should print out like this:

process 1: 100000
process 2: 300000
process 3: 600000

View 1 Replies View Related

C++ :: Mortgage Calculator - Displaying Months In Correct Order

Mar 29, 2013

I need my code to display Month but it seems my code is skipping month's and not displaying 1, 2 3. It's going 1 , 3 ,5 and so on. This is the code i have for it

Code:
int month = 1;

And later on the code i have month++ That's my first mistake and i'm not sure how to possibly fix it. My second mistake is my Interest Paid output. This is the code i have for it

Code:
interestPaid = loanBalance*i;

This is on the while loop, but i'm not sure why it's not displaying the correct amount. It should display for month 1 = 500.00 , Month 2 = 498.28 and Month 3 = 496.55 and so on... However my code display's something close to it, but not that. i is my monthly interest rate. My code for it seems to be fine. If i can fix this two things i'll be able to finish the project. This is my entire code, how i can fix it so that my month is displayed in 1, 2, 3, etc.... and not 1, 3, 5, etc... And why my interest is not displaying what my professor has on his output screen (i provided the first three months on top in bold) If i can fix those things i'll have the rest. Here's my entire code

#include <iostream>
#include <iomanip>
using namespace std;
int main ( ) {
int month = 1;
// Holds the user's amount of loan.
double loanAmount;
// Holds the user's interest rate.
double i;

[Code] ....

View 3 Replies View Related

C/C++ :: Tokenize Mathematical Expression - Garbage Value In String

Feb 14, 2014

I wrote a program that tries to tokenize a mathematical expression, inserting the tokens in a list of strings. The list is as follows:

typedef struct listOfStrings {
    char **array;
    int size;
} ListOfStrings;

There is even a function to initialize the listOfStrings. The thing is: I'm printing a token every time it is complete and every time it is inserted in the list. The output is okay. However, when all tokens are processed and I call function print_list_of_strings to print the tokens again, the first token is printed with a leading garbage value if the input for the program is "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3". How is this possible? The code for printing the list is as follows:

void print_list_of_strings( const ListOfStrings *const lPtr ) {
    int i;
    int numberOfElements = lPtr->size;  
    if ( numberOfElements != 0 ) {
        for ( i = 0 ; i < numberOfElements ; ++i ) {

[Code] ....

The list just prints --- if it's empty, although this isn't the case for the program I'm writing. Also, if the input is "1 + 2", everything goes fine. The code for inserting at the list is:

int insert_at_end_of_list_of_strings( ListOfStrings *lPtr, const char *const str ){
    int lengthOfStr = strlen( str );
    int numberOfElements = lPtr->size;  
    if ( ( ( *( lPtr->array + numberOfElements ) ) = ( char * )malloc( ( lengthOfStr + 1 ) *
 
[Code] ....

View 5 Replies View Related

C++ :: How To Do CRC Calculation For Base64 String

Aug 1, 2013

I am trying to calculate a CRC of a Base64 string.I give you the correct checksum : 2942042514...And now the string :

AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13
m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR
lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH
[code]....

I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.I don't want C++ code source, but I am searching for the method or algorithm to find it. If you want to know, this string in base64 contains an string compressed in zip, which contains an UTF16 XML. I want to modify information, and modify Adobe Projet (prproj)

View 6 Replies View Related

C/C++ :: How To Do CRC Calculation For Base64 String

Aug 1, 2013

I am trying to calculate a CRC of a Base64 string. I know the answer of the checksum, but I don't how to calculate it (It is for Adobe project).

I give you the correct checksum : 2942042514

And now the string :
AQAAAAAAAABsYAAAAAAAAENvbXByZXNzZWRUaXRsZQB4nO0d2XIaSbI+hZ13
m0NCR0QNE7KOHcXKlkMwtnhyIIRkdjGwgGxpP35386jqursRsk0zQygkd+dR
lVmVmZVdl//3Xyl+E4/iixiJivgqBmIm5mIoJmIsfhW/iLp4LWrwbwUwY9EH
+C1gx+KesH+IjjgTr4Bqj2h+Ey0hxRHQTMQNcHwSV/A0EYsA3oFSFlDngDAf

[Code] ....

I tried CRC 16, 32 and with polynomial 0xEDB88320L, and with all these tries, I cannot find the correct checksum, it is my main problem.

View 12 Replies View Related

Visual C++ :: Calculate Prime Numbers In Order

May 12, 2013

So if i write a Loop to calculate Prime Numbers in order, is there any way possible for this to happen in a shorter period of time.

The loop that i constructed took about 11hrs on a Win 7 2GB ram machine to calculate about 150,000 primes, could this be done any faster................

View 14 Replies View Related

Visual C++ :: Retrieving Size Of Each String In Order To Produce A New Buffer For Concatenated String

Feb 25, 2013

What is the efficiency of the two assignments (line 1 and 2), i.e. (function calls, number of copies made, etc), also the Big O notation. I know there are function calls for retrieving the size of each string in order to produce a new buffer for the concatenated string...any difference between line 1 and 2 in terms of efficiency?

String s("Hello");
String t("There");
1. s = s + t;
2. s += t;

View 3 Replies View Related

C Sharp :: Input String Was Not In Correct Format

Apr 28, 2012

List<Byte> Pt_split(string plain)  {
            List<Byte> pb = new List<Byte>();
            // Byte p;
            string p;
            int temp = 0;
            if (plain.Length % 2 != 0)

[Code] ....

View 2 Replies View Related

C :: Pointers And String Manipulations - Finding Correct Path

Mar 11, 2014

i've been writing some code for an assignment and it is mostly about pointers and string manipulations. It runs but crashes and I think it might be from over- valuating some strings maybe not. I have written in check points to make sure each function passes through but quits at findFirstPath loop, I had kept running the program through as i added more and more code. It had stopped when I near finished I believed it to just be because I hadn't finished the functions I called.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#define MAXSTRING 10
#define TRUE 1

[Code]....

View 3 Replies View Related

C :: Strcpy - How To Update Old String In Stars Array With New That Includes Correct Letters

Apr 25, 2013

This for loop replaces the stars ******** in an array that contains a word to be guessed with the correct letter (c) that the user inputs if the word contains that letter.

Problem: After every guess the same hidden string of stars ******* is displayed instead of ex: ***W**** (assuming W was entered by the user)

How can I update the old ******** string in the Stars array with the new string that includes the correct letters chosen, so after every correct guess at a letter in the word a new string is displayed including the correct letters chosen?

I'm pretty sure I have to use strcpy but not sure how to implement it using a loop.

Code:
for(i = 0; i < strlen(unscrambledWord); i++) {
if(unscrambledWord [i] == c) {
Stars[i] = c;
} }

View 1 Replies View Related

C# :: Unable To Implicit Convert Type Int To String Though Declared Variables As String

Mar 26, 2014

Ok, so I'm writing this code and when I build it keeps saying cannot implicitely convert type int to string even though I declared my variables as string. Why is it giving me this error?

private static string Repair()
{
string result="";
string beep;
string spin;
Console.WriteLine("Does your computer beep on startup?:(y,n)");

[Code]...

View 3 Replies View Related

C++ :: Printing String In Reverse Order

May 14, 2014

How to print a string in reverse order(for example: "today is Wednesday " to "Wednesday is today"). My professor said we should begin with a null string and build it one word at a time.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int nwords(string);

[Code] .....

View 1 Replies View Related

C++ :: Convert And Return C Format String To String?

Jun 8, 2014

heres the function:

string ToString ( const char * format, ... )
{
char buffer[256];

[Code]....

these function do the same of the sprintf() function. but instead we use a variable for add the result, i want to return the result. when i use it:

string f;
f=ToString("hello world");
gives me several errors:
"error: crosses initialization of 'std::string f'"
"error: jump to case label [-fpermissive]"

View 7 Replies View Related

Visual C++ :: How To Convert UTF-8 String To Unicode String

Jun 15, 2013

I am using Visual Studio 2008. I just wonder if there are any library function in Windows SDK or MFC, or from third-parties, that can convert a UTF-8 string into Windows Unicode string(used in CString object).

Can MultiByteToWideChar or ATL String conversion macro like A2W to the conversion?

View 1 Replies View Related

C :: Sorting Number As A String By Ascending Order

Jul 2, 2014

make my program sort data.in this case number that i declared as char(not string, my bada)if i have

name1
number 2500
email

name 2
number 2400
email

i need to put that this way:
name 2
number 2400
email

name1
number 2500
email

i saw that can be done with qsort but when i try it it doesn't work.

Code:

typedef struct {
char nome[MAX_GERAL], email[MAX_GERAL], morada[MAX_GERAL], postal[MAX_GERAL], numero[MAX_GERAL], geral[MAX_GERAL];
int telefone, FP, SD, AM1, ALGA, CM;
}dados;

code to add info i need to sort "numero"

Code:

void adicionar(dados* contacto){
if (i<total) {
printf("
Introduza o Nome: ", i + 1);
scanf(" %[^

[code]....

View 7 Replies View Related

C++ :: String Array Sorting Into Alphabetical Order

Apr 14, 2014

I am trying to read information in from a file, each line of which contains a name in the form 'last, first middle'. I can successfully open the file and read it into an array that is roughly 2500 string in size. The problem comes when I try to sort the array into alphabetical order. I am using a sorting algorithm that we were instructed to use, found in our book. It is shown in the code. I would add the file that needs to be opened, but it is a few thousand lines long.

The error I am getting is:
Unhandled exception at 0x00A28628 in PeopleSearch.exe: 0xC0000005: Access violation reading location 0x00CC400C.

and I know it has to do with the sorting algorithm from using break points and running the program with that section commented out. I am stumped to why it is giving this error, as it seems that it is trying to access the array outside of the bounds of the array, but it shouldn't be

Here is my code:

#include<iostream>
#include<string>
#include<fstream>

using namespace std;
int main() {
string NameArray[2500], filename; //declare array and file to open

[Code] ....

View 2 Replies View Related

C++ :: Swap Function To Put String In Alphabetical Order

Nov 10, 2013

So I been working on this c++ project and I need to be able to take three seperate strings and send them to function to put them in alphabetical order through a-z and use the swap function to return them in order. I been searching for problems like this but I haven't fame across any. I can copy my code onto here as well as a more detailed description of what I'm needing to do onto here if needed.

View 4 Replies View Related

C++ :: Sorting Vector String In Alphabetical Order

Oct 26, 2013

I know there is a function in algorithm class called sort() but I need to sort ignoring the case of the alphabet

Is there any function that does that?

View 2 Replies View Related

C# :: Using Mathematical Functions

Dec 5, 2014

like other programmers I am also new to the world of programming. So, I have to use a mathematical function in Cmath.

The function is z1 = Sin2α + sin5α - Sin3α / cosα+1-2sin*2(2α)

z2= √x*3 + 3 / x*3 - 3
My results so far...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

[Code].....

View 6 Replies View Related

C++ :: String Copy - Program To Reverse Word Order In Sentence

Apr 2, 2012

I am trying to write a program that takes a sentence and reverses the word order.

For instance This is a Bird would become Bird a is This

Code :

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main (void) {
char input_buffer[1024];
char middle[1024];

[Code] ....

View 3 Replies View Related

C++ :: Take (mathematical) Inverse Of Array?

Feb 17, 2014

I need to take an array, and get the inverse of it (basically, just how you would take an inverse of a function in math). I need to do it where, if a[i] = x, b[x] = i. I would just copy from array a to array b in a function.

View 10 Replies View Related

C++ :: Mathematical Library - OOP Linker Errors?

Apr 21, 2014

I've just started coding a "Mathematics" library for my own, just to practice some OOP concepts, but sadly I didn't get too far with it before the first errors appeared. That is, I created a Matrix.H and Matrix.CPP file (separate class) in a "Linear Algebra" folder.

However, when I run the code I get the following (linker?) error:

#include <iostream>
#include "Matrix.h"
using namespace std;
int main() {
Matrix<int> A(7,5);
int row[] = {5, 10, 9, 11, -5};

[Code] ....

I am using Visual Studio 2012 (stating this in case it could be related to the reason for which I get the error).

View 2 Replies View Related

C++ :: Mathematical Operations With Digits In Strings?

Feb 11, 2015

I'm working on a class project, and I'm having a difficulty. Suppose I have: string a = "21" and string b = "30"; normally, a+b=2130 (i.e concatenation of the characters in the string) but suppose I want a+b=51 (i.e. numerical addition) how do I go about this?

View 1 Replies View Related

C++ :: Program To Complete Mathematical Operations Using Matrices

Jul 10, 2014

I've been assigned to build a program which completes mathematical operations using matrices. I have to use dynamically allocated 2d arrays, and can only use * to dereference and not []. I have this code so far, but the multiply_matrix function does not work with most values. I've looked at other similar posts, which have a similar algorithm to mine, but mine does not work for some reason.

/*
*(*matrix(matrix+i)+j)
*/

#include <iostream>
//for sleep() which allows user to see messages before screen is cleared
#include <unistd.h>
using namespace std;

[Code] .....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved