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


ADVERTISEMENT

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

C++ :: Adding Mathematical Expression In Binary Tree

Jul 23, 2013

I want to add mathematical expression in a binary tree but I have some problems with the algorithm. I found this one:

-If the current token is a '(', add a new node as the left child of the current node, and descend to the left child.
-If the current token is in the list ['+','-','/','*'], set the root value of the current node to the operator represented by the current token. Add a new node as the right child of the current node and descend to the right child.
-If the current token is a number, set the root value of the current node to the number and return to the parent.
-If the current token is a ')', go to the parent of the current node.

Here is the code that I made so far:

template<class T>
void Tree<T>::Expr(Node<T> *node, char expr[], int &i) {
i++;
T x = expr[i];
if(x == '(') {
node = node->Left;

[Code] ....

I know that it is a big mess and it doesn't follow the algorithm but this is the problem. For example if the token is '(' I go to the left child of the current node. Then lets say that the next token in the expression is a number. I add this number to the current node and I must go back. But how can I go back to the parent? I will go back to line 13 and the program will end. What should be the structure that I must use?

View 1 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

Visual C++ :: How To Print Mathematical Series On Screen

Nov 24, 2013

How do I print a mathematical series such as

1 + 2/2! - 3/3! + ...... n/n! //n is read from user

Not only we need to print the series on the screen but at the same time find the sum using simple loops.

View 1 Replies View Related

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 View Related

C++ :: Evaluate Mathematical Expression That Is Already Formed In Binary Search Tree

Apr 23, 2013

The point of my code is to evaluate a mathematical expression that's already formed in a Binary Search Tree. : ((6+5)-3)*(2/1)=?

I've read other forums and they usually use cout, cin and << >> but I'm still in the learning process so this is basically primitive coding.

Anyway, The recursion is already correct (I think). My problem is how to return char* or should I say an element which has 2 or more digits.

typedef struct cell{
char elem[max];
struct cell *left;
struct cell *right;
}celltype, *node;
node A;
char* evaluate(node *A) //passed as evaluation(&A);

[Code] ....

And the reason that I'm using char is because the operators are also elements in different nodes.

The code above is actually the result when I remembered that you can't return 2-digit char.

The code below is before I remembered that. It works when all results are 1 digit numbers.

typedef struct cell{
char elem;
struct cell *left;
struct cell *right;
}celltype, *node;
node A;

[Code] ....

View 1 Replies View Related

C++ :: Changing Integer Into New Integer With Simple Mathematical Operations?

Jun 15, 2014

changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).

View 4 Replies View Related

C/C++ :: How To Access Linked List Functions From Stack Class Without Functions

Mar 20, 2014

I'm a little confused by my programming assignment this week. I've been working at it Wednesday and I've made progress but I'm still confused as to how I'm supposed to do this. The class I made is called Stack, and it's derived from a template class called StackADT. We also utilize a class called unorderedLinkedList, which is derived from a class called linkedList.

We're supposed to implement all of the virtual functions from stackADT in the Stack class. The Stack data is stored in a an unorderedLinkedList, so what I'm confused by is how to implement a few of the Stack functions because there are no functions in unorderedLinkedList which we could call to manipulate the data.

As you can see from my attached code, I'm really confused by how I'm supposed to implement the pop() and top() functions, and I also think my initializeList() function is wrong. We don't have any similar functions in unorderedLinkedList to call, so I'm at a loss of how i'd access my unorderedLinkedList. My initial thought was to call the similar functions in the class that unorderedLinkedList was derived from, linkedList, but I'm unsure of this is what we're supposed to do, or if theres actually a way to access my unorderedLinkedList without having to use the functions from the base class.

NOTE: We're not allowed to modify stackADT, unorderedLinkedList, and linkedList.

Stack.h

#include "stackADT.h"
#include "unorderedLinkedList.h"
template<class Type>
class Stack: public stackADT<Type>{
template <class T>
struct nodeType
{
T info;
nodeType<T> *link;

[Code]...

View 3 Replies View Related

C/C++ :: Array Of Functions Pointing To In Class Functions With Arduino

May 3, 2013

At the moment im trying out with pointing to an array of functions. I got this working as following:

typedef void (* functionPtr) ();  
functionPtr functions[2][2]={{do11,do12}, {do21,do22}};    
void do11(){DEBUG_PRINTLN("11");}
void do12(){DEBUG_PRINTLN("12");}
void do21(){DEBUG_PRINTLN("21");}
void do22(){DEBUG_PRINTLN("22");}    
void loop(){
         A=0;
         B=1;
         functions[A][b]();
}  

But now I'm trying to use this to point to a function inside a class so instead of do11, i want to be able to point to Basic.Do11. Somehow this doesnt work and I keep on getting this message:

error: argument of type 'void (Basic::)()' does not match 'void (*)()'

View 2 Replies View Related

C :: Getting Used To Functions

Jul 24, 2013

So In my studying of C I am starting to come across more programs with functions in them.This particular program asks for two numbers, and calculates the sum of all the squares of the two numbers and the numbers in between them. I am confused about the get_int() function.

Code:

/* checking.c -- validating input */
#include <stdio.h>
#include <stdbool.h>
int get_int(void); // validate that input is an integer
bool bad_limits(int begin, int end, int low, int high); // validate that range limits are valid
double sum_squares(int a, int b); // calculate the sum of the squares of the integers a through b
}

[code]....

So in that get_int() function, it's pretty simple if scanf returns 1, otherwise... another while loop call the getchar() function, which is assigned to the variable ch. So say I enter 'a' for the lower limit, this is what happens:

Code: Enter the limits (enter 0 for both limits to quit):
lower limit: a

a is not an integer. It seems as if getchar() somehow "got the character" from scanf(). There's no way that getchar() could have been simultaneously reading my input, because that function is not even called until scanf has already not returned 1. So I'm confused how that happened. I was under the impression that getchar() got input from the keyboard, which would lead me to think that I would be prompted to input something again when getchar() is called, before putchar() prints the scanf input. But this is obviously not the case.

Also, I'm curious about that comment beside putchar(ch) that says //dispose of bad input. I recall a long time ago on these forums, someone told me something about how once scanf has read input, that input is like... stuck to scanf.. So does putchar() not only print the input from scanf/getchar, but also unload it from scanf, so to speak?

View 4 Replies View Related

C++ :: Get And Set Functions

Feb 1, 2014

i'm stuck with functions

#include <iostream>
#include <functional>
using namespace std;
template <typename T>
class property

[code].....

the code works like a charm. but imagine that i need more with Get and Set functions, how can i connect them to the T PropertyValue on class property?

View 12 Replies View Related

C++ :: How To Get A Set Of Functions To All Use The Same Template

Dec 11, 2013

I'm getting tired of writing Code: template <typename T> everywhere.

Is the only solution to encapsulate all my desired functions in a templated class?

View 7 Replies View Related

C++ :: How To Declare Functions

Aug 19, 2013

How to declare functions in C++

View 1 Replies View Related

C :: Use Of Functions In Top / Down Approach

Mar 25, 2014

I'm getting a bit lost in calling functions correctly. The assignment says to, reprogram this assignment using functions and include the additional features identified below -

Design your program so the main function invokes/calls functions to perform the following tasks:

4) sort the arrays in ascending order by student ID number

Here's what I've got thus far and I'm confused cuz I might be calling my function incorrectly.

Code:
#include <stdio.h>
#define MAX_ENTRIES 50
void s_ID (int student_ID[], int test_score[], char char_val[]);
int main (void) {

[Code] .....

View 7 Replies View Related

C :: Adding New Functions

Jul 3, 2014

I am new to c and I have come across a problem when adding other functions to a programme and printing the values. The question I am attempting to solve is :

The following function computes ex by summing the Taylor series expansion to n terms. Write a program to print a table of ex using both this function and the exp() function from the math.h library, for x = 0 to 1 in steps of 0.1. The program should ask the user what value of n to use.

double taylor(double x, int n) {
int i;
double sum = 1.0;
double term = 1.0;
for (i=1; i<=n; i++) {
/*Or we could have written: */
term = term * x / i; /* term *= x / i; */
sum = sum + term; /* sum += term; */
}
return sum;
}

My code is

Code:

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/*Taylor series for e*/

[code]....

code prints out the values for exp, but it gets stuck in the Taylor function and I'm not sure how to solve it.

View 2 Replies View Related

C :: Passing Into Functions

Feb 18, 2013

forget everything from before. It came out of confusion regard the supplier functions. dis_s() and read_s() the part functions work and are not any different really.

Code:

#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define MPS 10 //Max Part Size
#define MSS 10 //Max Supplier Size
}

[code]....

when I run the dis_s() function it just prints out garbage until it segments. starts with a bunch of 0 and newlines until it starts printing locations on my computer...... it worked on campus with debian and I only copied it from gmail to my computer so I really don't understand whats up(im on mint).

View 7 Replies View Related

C++ :: Functions Does Not Return New Value

Jul 24, 2014

In my program below, in the getage and get level functions, if an incorrect input is entered, then the correct one is entered after, it still returns the bad input back to main.

#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

[Code] ....

View 7 Replies View Related

C++ :: Use A New Class On Functions?

Feb 14, 2015

how use a new class on functions?

class test
{
public:
int a=0;

[Code]....

i did something like these with my image class, but i get wrong results.

View 6 Replies View Related

C/C++ :: Use The Same Variables Between Functions?

Mar 6, 2015

I'm trying to use two variables for two different functions.

#include "stdafx.h"
#include <iostream>
#include <cstdlib>

[Code].....

Every time screen2() runs it always outputs "Numbers entered were 0 and 0". I want the numbers that were entered in by the user in screen1() to be displayed.

View 2 Replies View Related

C/C++ :: Functions Are Undefined?

Sep 20, 2014

Not quite sure what the problem is here. I have all my functions in my class header file, and I believe I have them declared at the top, but it is telling me that I do not. The project is simply to use set and get functions to display the date.

#include "stdafx.h"
class Date
{
public:

[Code].....

View 5 Replies View Related

C++ :: Including Outside Functions Into Classes?

Mar 6, 2015

I have a hpp file with a list of inline finctions like this:

Code:
inline int check() {
return 1;
}
inline int check_1() {
return 1;
}

... What I would like to do is to include them into several unrelated classes. How can I do this. Can I just add the hpp inline functions in headers of my class containing files or not. I mean if they are not defined as class functions how can they be called. I don't understan the logic.

View 2 Replies View Related

C++ :: Printing Text With Functions

Feb 27, 2014

Any way to make a function that prints something. i wanted to make a function for

Code:

cout << " PAUSE MENU " << endl; cout << " 0. Resume Game " << endl;
cout << " 1. Commands " << endl;
cout << " 2. Controller Setup " << endl;
cout << " 3. Bottles of Beer " << endl;
cout << " 4. Quit " << endl;
cout << " What is your Choice - ";
cin >> userinput;

So i wouldn't have to retype it again in the loop, i would just call the function. but it seems whatever i try it doesn't display the text. i've tried making a function with no return time like this " Void Pausemenu(); " but that just goes blank.

Code:

#include <iostream>
using namespace std;
//This function displays different results based on the users input
int menu(int menuchoice);
int main()

[Code] ....

View 4 Replies View Related







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