C/C++ :: Binomial Expansion - Simple Math String Into Array
May 5, 2014
My project is binomial expansion. I want to allow for basic string input. Then, I must process the string for input into the other portions of my program. To make the binomial expansion calculation simpler I am using two separate arrays for the first and second term of the binomial expansion. The integer array structure for each term is [{numerical Coefficient of term}, {exponent of variable a}, {exponent of variable b}, {exponent of variable c}, ......{exponent of variable x}, {exponent of variable y}, exponent of variable z}].
So, if the user doesn't use a variable it's exponent's value will = 0. The reason why I set my array up like this is so it would be very simple to raise each term to the power of n, or (n-k) (Multiple variable exponents by number, raise #coefficient to the power). It would also be easy to combine the terms to get one term. terms[0] are multiplied, all other terms are added.
My issue is translating a basic mathematical string consisting of only Integers, letter, parenthesis, and '^', into the array. I find difficulty mainly due to the '^' symbol. I know how to find the array index for a given letter. termArrayIndex = (int)((char from string) - 'a' + 1)
the main things causing me issues
-The issue is knowing which numbers to multiply by the array.
E.g. (_(_____)^#(__^#__)^#____)^#
I started by finding the first ')', then finding the preceding '(' and processing that string. I would then remove said string and use recusrion to go through the whole string. This method doesn't work because there is data loss upon removal of processed string. EG (__(__)^#) =remove innermost string and parenthesis=> (__^#) != (__()^2,
-maybe enter all terms, leave parenthesis, then process exponents separately...
-I may be able to find the # of separate terms by seeing # of times a '(' comes after a ')'
This is by far the most difficult part of the problem for me. But that also makes it the most fun. I want it to be able to handle all variation of these basic mathematical expressions.
View 3 Replies
ADVERTISEMENT
Dec 1, 2014
This is an example of how sub string and math can be used to make logical decisions without using if/elses or switches. It works because of this equation
(x + |x|)/x = 2 if x > 0 and = 2 if x < 0.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main() {
//declaration of variables
[Code] ....
View 1 Replies
View Related
Mar 27, 2013
I'm trying to write a code which will generate numbers for a binomial coefficient from a number interval [2-10], i think it should look like this:
n=2
r=2
n=2
r=3
n=2
r=4
n=2
r=5
.
.
.
n=10
r=10
-The program should stop here.
This is badly written, but it still has the basic idea in it.
#include <iostream>
using namespace std;
int main () {
int n=2;
int r=1;
[Code] ....
View 1 Replies
View Related
Mar 6, 2015
The assignment is to write a program that statistically computes similarity of C syntax with another program; a same and a different. The one used here is in C language, it's called Battleship.cpp. The program must open a file and read line by line for keywords and then produce statistics. The reason my code is not running is the fopen function is failing and it goes to return -1. I am using MS Visual Studio 2013 and there are no compiler errors after turning off deprecation. I do see, however, this error UMEngx86.dll'. Cannot find or open the PDB file. The file being opened is in my source folder.
Code:
1
2
3
4
5
[code]....
View 4 Replies
View Related
Jul 13, 2013
I wrote a code which checks if there are any single numbers in an array.e.g.In the next array there is a single number - "3" 4 1 4 3 4 1..Here is an array which doesn't have single numbers in it: 4 1 4 3 3 1
Code:
#include <iostream>
using namespace std;
int single (int arr[], int size)
{
int couple=0;
[Code]....
First I thought to double the number of couples I'll get from my search and find some connection to the length of the array, but it hasn't worked out (signed red).
View 9 Replies
View Related
Oct 17, 2014
I have a rather large project which uses a float array for OpenGL but I believe I am reproducing the problem with a simple example below.Essentially I am getting access violation and HEAP CORRUPTION errors when I execute the code below.
#include <iostream>
#include <string>
#include <sstream>
int main(int argc, char** argv) {
std::cout << "Please enter in the size of the array you would like to create:
[code].....
View 2 Replies
View Related
Oct 24, 2013
I am required to create a simple candy crush game.
I am this stage where I am required to print the 'box' for navigation purpose at the center of the board once the program initializes.
Here is the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//FUNCTION: Draw the Board
[Code].....
I understand that the sequence could be to clear the screen and print the whole board with the indicated marker.
*Yes I am required to move the box in later part of the program but for now, I just need to get the box to show up at coordinate
Code: board[5][5]
I am stuck ...
View 11 Replies
View Related
Sep 22, 2014
How would one write 3^i without using .math? (i being numbers 0-9)
More specifically, this is what I have:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int x, n, answer1, first;
x = 3;
n = 10;
first = 1;
[Code]....
And this is what I want it to produce:
1 0 1.0
3 1 0.333333343
9 2 0.111111112
27 3 0.037037037
81 4 0.012345679
243 5 0.004115226
729 6 0.001371742
2187 7 0.000457247
6561 8 0.000152416
19683 9 0.000050805
I believe I am only having troubles with the first column,
View 10 Replies
View Related
Feb 8, 2013
I have a problem with entering math functions in my Bisection method algorithm program. I just don't know how can I make the function that I enter in my GUI app to go from the GUI to the loop and find the root.As far as I googled I only find codes that you need to pre-enter a function in the double/float.
For example:I have a function f(x) = x^3 - cos(x) - x - 3; and I want to enter that function trough the GUI i made in c++..So this is the main code.
#include "bisection.h"
#include "ui_bisection.h"
#include <QFile>
#include <QString>
#include <math.h>
#include <algorithm>
bisection::bisection(QWidget *parent) :
[code]....
View 11 Replies
View Related
Mar 21, 2013
Working on a program that converts infix to postfix math formulas. Ive successfully converted the infix to a postfix notation but now i am having trouble solving the equation from the postfix form. Im trying to set a result equal to three variables as shown below:
result = op1 ch op2;
where op1 and op2 are numbers and ch is the operator (+-*/) depending on what the user entered into a string. The error im getting is that it expected a ";" before postfix so clearly it doesn't understand what im trying to do. how to put the answer from op1 ch op2 into result.
View 4 Replies
View Related
Apr 14, 2013
How can i solve a problem of sin(x) without using any math.h and only using my own declared function.
#include <stdio.h>
int fact (int a) {
int i;
int k = 1;
for (i=1;i<=a;i++)
[Code] ....
View 3 Replies
View Related
Nov 4, 2013
Here is my objective: Write a c program that calculates the value of a mathematical expression comprised of positive numbers and the operations "+" and "-" . Specifically, first prompt the user to input an expression, read itin as a string, and then print the value of the expression. You may assume that the expression does not contain spaces, maximumsize of the expression (including digits and operators) can be 20,and that all numbers are single digit numbers.
Note that, the digits would be read in as characters; you will need to translate them to numbers (recall the ASCII table). Implementation Requirements:
Write a function called "evaluate" that takes as input a mathematical expression(as a string) and returns the value of the expression. The prototype of the function is: intevaluate(char expr[]);
Sample Output:
Input: 4+2-1+7 Output:12
Code:
int main()
{
char expr[21];
int a,ssum;
printf("Input: ");
scanf("%20s", expr);
[Code] .....
the program runs, but the output is not coming out correct.
View 11 Replies
View Related
Mar 22, 2013
I am new to c programing and I had spend 2 days on a program and I can't fix the error:
Code] ....
gcc Test.c -o Test.exe
/tmp/ccZkbk0V.o: In function `f':
Test.c:(.text+0x2f): undefined reference to `sqrt'
collect2: ld returned 1 exit status
Tthe program I am working in is:
#include <stdio.h>
#include <math.h>
int f(int x){
return (sqrt(4.0 - x*x));
[Code] .....
View 2 Replies
View Related
Dec 22, 2013
Is there any way to do date math using standard C libraries? I looked around in the time.h but didn't see what I needed.
What I need to do is be able to add a certain number of minutes to a date and have it give the current date/time. For example, add 15918765 minutes to 01/01/1980 00:00 and have it tell me 04/07/2010 4:45PM. I really don't want to write this myself or go platform-specific.
Does this exist somewhere or am I SOL?
View 13 Replies
View Related
Apr 30, 2013
I wrote a program that solves an equation of two numbers, but in addition to that, I want it to be able to continue to solve longer equations. Ex: ( solves 2 * 4, or 2 * 4 - 5).I want to put this part of the program's result into a variable and go from there. How do I place the result of the calculation into a variable, and where would it go?
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
int a;
scanf("%d", &a);
char s[2];
scanf("%s", s);
int b;
scanf("%d", &b);
}
[code]....
View 4 Replies
View Related
Oct 14, 2013
I am trying to compare a math operator with a variable, but i keep getting this error:
postfixDriver.cpp:93: error: expected primary-expression before ')' token.
I'm sure it's probably something simple, but im just not seeing it. Here is the code snippet:
while (strlen(str) != 0) {
split (str, token);
Postfix stack;
double a;
double b;
double answer;
if (atof(token)==0.0)
[Code] .....
View 2 Replies
View Related
Feb 11, 2014
math part.
The equation I need to use is: payment = [(rate * (1 + rate)^number payments ) / ((1 + rate)^number of payments -1)] * loan
Also, the value of rate in the above equation is (interest/12)/100. So 12% annual interest would be 1% monthly interest.
heres my code:
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
[Code].....
View 4 Replies
View Related
May 21, 2014
I'm having trouble with getting a sine function to work. All variables are defined earlier in the same section. I have the code in a button (where I figured it would go) but I get the following error:
WindowsFormsApplication2.Math does not contain a definition for 'Sin'
For reference, I am using Microsoft Visual Studio Express 2013, and am coding a Windows Forms Application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
[Code] ....
I've tried other functions as well (abs, sqrt, etc.) to no avail, as Math only seems to pop up with two options: Equals and ReferenceEquals.
View 2 Replies
View Related
Aug 17, 2014
I have to create a program that read two numbers and the math operators +, -, * and /. After that I should print the operation required. But I tried to declare a <symbol> variable as char type, without sucess...
Here goes my script:
float num1, num2, result;
char symbol;
printf("Write two numbers:
");
[code]....
View 1 Replies
View Related
Sep 3, 2013
Its a basic math function using the exponential growth formula which is correct but the computer is not outputting the right numbers.
Code:
#include <stdio.h>
#include <math.h>
int main() {
int blanketsquares, num1, num2, blanket,remainder;
[Code] .....
View 6 Replies
View Related
Nov 16, 2014
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void correctResponse(void);
void incorrectResponse (void);
void multiplication( void ); // function prototype
[Code] ....
// end function multiplication
// It keeps crashing. How do I compile the responses into a grade?
View 5 Replies
View Related
Nov 26, 2014
The user will be allowed to pick:
-the number of problems they want to do
-the type of problem (addition, subtraction, multiplication, division)
-the range of numbers for the problems (like 0 to 9, -100 to 100, etc.) [random numbers in the range]
Your program will then display the given number of problems and get the answer from the user. It will tell the user it they are correct or not. If they are incorrect, it will print the correct answer.
After the given number of problems are displayed, the program will give the user the final number correct and percentage correct. The user will be asked if they want to go again. If so, you will reprompt the user for all the information and run again.
I came up with code thinking I was going in the right direction but it doesn't work correctly at all. We have to use functions. My main issue is how do i call variables from another function so all of the functions work together. I repeat I don't understand parameters and calling functions. here's the code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int get_user_range(int &x, int &y);
int get_random_number ();
[Code]......
View 1 Replies
View Related
Feb 2, 2015
I currently am stuck at getting the needed outcome data from my RFID card. I got it decoded but now I need to do a few more things in order to get the final card number off the back of the card.
The cryptic value was E********B**0**E** (covered to protect card)
Decrypting it turned into 0000003048D1263B
Now I have 3 more steps to take in order to get to my wanted card number.
Quote
Step 1) Mask off the lower 20-bits (which should give me 0x1263B) I am unsure of how to go about doing that using C++.
View 2 Replies
View Related
Mar 6, 2015
The values in my file are 5,5,332,156,11,0,555,32,8,9 .... the computer when I scan and read is missing the first 5 and only showing 9 values which is messing up my mean and standard deviation. But when I have them put in order all of my numbers show up:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 100
void bubbleSort( int * const array, size_t size);// prototype
[Code] .....
if possible, why won't the median work. I have it commented off as of right now....
View 2 Replies
View Related
Oct 21, 2013
I am making a math game program that simple and need to have a user input a name and then that name.txt is brought up and use variables from the text to add to their score. heres my code kinda long.
#include <iostream>
#include <cmath>
#include <cctype>
#include <string>
#include <ctime>
#include <cstdlib>
[Code] ....
View 10 Replies
View Related
Feb 2, 2015
I currently am stuck at getting the needed outcome data from my RFID card. I got it decoded but now I need to do a few more things in order to get the final card number off the back of the card.
The cryptic value was E********B**0**E** (covered to protect card)
Decrypting it turned into 0000003048D1263B
Now I have 3 more steps to take in order to get to my wanted card number.
Step 1) Mask off the lower 20-bits (which should give me 0x1263B) I am unsure of how to go about doing that using C++.
Step 2) Divide by 2 to strip off the lower parity bit (which should be 0x931d). And again, I'm unsure of how to go about doing this in C++.
Step 3) Convert hexadecimal value to decimal value (which would equal my wanted card number). This should be easily done using C++ at this point - though hard to confirm that since I am on step 1).
Code:
const char* original = "0x931d";
unsigned long n = std::strtoul(original, nullptr, 16);
All of this looks to me like RegEX does to most people - complicated and not understanding why it does what it does but gives the correct output.
View 2 Replies
View Related