C :: Scanning Equations / Functions Into Program

Nov 15, 2014

I have to make a numerical integration program, how I can write my code so that the user is able to write their own function that they want to integrate?

E.g. they would see the message: 'please enter your function' and would be able to write whatever they wanted e.g. 'x +5' then this would then be integrated by the program.

I have already written a program that can integrate a known function but would prefer that the user could choose their own.

View 2 Replies


ADVERTISEMENT

C :: Program That Solves Math Equations

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

C :: Working With Equations

Nov 19, 2013

I need to find out all the possible equations which are same of a given equation. For eg. a+b+c-d and b+c+a-d are same. So if the user inputs a+b+c-d then the output will be all the possible equations that can be formed from the given equation, viz:

a+c+b-d
c+a+b-d
-d+a+c+b

etc

i.e the program should rearrange the operands and operators in such a way that it should give the same result.

View 5 Replies View Related

C++ :: Equations And Intersection Point

Aug 17, 2013

Program which accepts two lines and and determines their intersection point and whether they lie within a circle, also given interactively. I'm racing against time and I've racked my skull to no avail

View 2 Replies View Related

C :: Calculate The Solutions Of Quadratic Equations

Oct 22, 2014

I have a task to find errors in this long line of code in order to correctly calculate the solutions of quadratic equations.

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

/***********************
* Input / Validation
***********************/

/* Check numbers of arguments, and read input */
validInput = (argc = 4);

[Code] ....

Is a section of the code (the first section). And as you can probably guess, it goes on to calculate for a > 0 etc...

I dont really understand what the validinput section is saying? And a, b and c are never defined so Xcode is just saying a,b,c,root1,root2 are uninitialized and I also dont know what means. Do I need to define these values?

Code:
int main(int argc, char *argv[]) {
int validInput, solution_type;
double a, b, c, root_1, root_2, q;

[Code] ......

View 9 Replies View Related

C :: Calculate Equations Just Like A Standard Calculator

Oct 23, 2013

The main point of the program is to calculate equations just like a standard calculator but I wanted to do it myself. I don't understand what the problem is right now but I've managed to create a program that asks for both values but somehow it doesn't want to ask for an operator (*, /, + etc). What's wrong with my code that the terminal skips the scanning part for the operator?

Code:

#include <stdio.h>
int main() {
int value1, value2, answer;
char operator;

[code]....

View 12 Replies View Related

C++ :: Determine Roots Of Quadratic Equations?

May 23, 2013

I have given following exercise in my cpp book: Determine the roots of quadratic equations

ax^2 + bx + c = 0

using formula

x = -b +(plus-minus) (root)b^2 - 4ac/2a

i don't now how to write such code...

View 6 Replies View Related

C++ :: Solving Linear System Of Equations Using Threads

Dec 14, 2014

I am trying to write a code that solves a system of linear equations such as A*B=C. My system has a dimension equal to 1600. The matrix A cab be separated into 4 sub matrices and each can be handled by a different thread. I tried to solve this using the following code:

int main() {
int count = 0;
//Inputing matrix A
ifstream matrix;
matrix.open("example.txt");

[Code] ....

Although the above code gives the correct answer, the time needs to find the solution is bigger than that needed without using threads.

View 1 Replies View Related

C# :: How To Multithread Port Scanning App

Jan 24, 2012

I'm creating a small port scanning app which use a port range defined by user.My problem with the code is that I find it not efficient enough meaning that it ping very slow, especially when ports are not responding meaning that I must wait for the timeout before continuing to next port.

I want to make this small app threaded. The problem here is that I'm kind of blank of how to implement threading in my program. This is my code which is a method which does the actual checking, the other part of the code is a simple button with for loop for advancing my port number.

Code:

private void ScanPort(IPAddress address, int port) {
using (TcpClient client = new TcpClient() {
IAsyncResult result = client.BeginConnect(address, port, null, null);

if (result.AsyncWaitHandle.WaitOne((int)nudTimeout.Value, false)) txtDisplay.AppendText("Port: " + port + " is open." + Environment.NewLine);
else txtDisplay.AppendText("Port: " + port + " is closed." + Environment.NewLine);
} }

I have read some basic threading tutorial but I just don't know how to implement this piece of code so I can check ports much faster.

View 3 Replies View Related

C++ :: Finite Difference Method For Partial Differential Equations?

Nov 10, 2013

Calculated by the explicit scheme. Produces some very large numbers.

task:

[math] U_t = 3 (1,1-0,5 x) U_ {xx} + e ^ t-1 [/ math]
[math] U (0, t) = 0 [/ math]
[math] U (1, t) = 0 [/ math]
[math] U (x, 0) = 0.01 (1-x) x [/ math]

Need to find a solution with accuracy [math] 0.0001 [/ math] on the interval [math] T = 1 / a ^ *, where a ^ * = max a (x, t) [/ math] Plot graphs of functions [math] u (x ^ *, t), u (x, jt ^ *) [/ math] where [math] x ^ * = 0.6, t ^ * = T/10, j = 1,2,4 [/ math]

explicit difference scheme is as follows:

([math] $ u_t ^ {j +1}-u_i ^ j) / tau = 3 (1,1-0,5 x_i) (u_ {i +1} ^ {j}-2u_i ^ j + u_ {i -1} ^ j) / h ^ 2 + e ^ {t_j} +1 $ $ [/ math]

code of the program:

int main ( void ) {
setlocale(LC_ALL, "rus");
int I = 10, J = 30, i, j;
double T = 1.0/ pow(3.3, 0.5), h_x = 1.0/ I, h_t = T/ J, epsilon = h_t + pow(h_x, 2), c;
double **u = new double *[I + 1];
for (i = 0; i <= I; i++) u[i] = new double [J + 1];

[code]....

displays the following:

[URL]

View 2 Replies View Related

C :: Scanning CSV File And Assigning Variable To It

Dec 26, 2013

How to scan a CSV file and assigned variable to each of the integer scanned in a csv file

an example of the csv file:
0001,40,,10

How do I scan the CSV file and assign 0001 to variable student id, the 40 to variable module 01,the 1 without input entered to module02 and 10 to module03

View 6 Replies View Related

C :: Scanning 2 Strings In Same Scanf Call

Nov 20, 2013

Somehow only str2 is successfully scanned and str1 is not printed

Code:

printf("
Please enter two times in this way xx.xx xx.xx now ");
scanf("%s%s", str1, str2);
printf("
%s - %s:
", str1, str2)); result : - str2:

View 3 Replies View Related

C :: Scanning Characters Into A Multidimensional Array

Mar 19, 2014

I have initialized a multidimensional array eg char fruit[5][10]...Then I would need to read in 3 words with spaces in between from user and store in fruit[5][10] e.g "pear apple orange"

The thing is that after typing orange, when I press Enter it still prompts me to enter more characters. How can I end the scanning of characters after orange ?

View 4 Replies View Related

C/C++ :: Scanning CSV File Into Array Of Structs

Mar 18, 2015

I need to scan a .csv file that contains the following info:

programming,03,60,141,01,W,2015
programming,03,60,141,30,W,2015
Algebra,03,62,102,02,S,2013
Religion,08,98,938,20,F,2014

So i made a struct:

typedef struct CourseInfo {
int courseID;
char courseName[50];
char courseCode[13];
char term[7];
} courseinfo;

Where course code is the 4 numbers after the name together and the term is the letter and year in the last two pieces of info. I got this to work:

int main() {
FILE *p;
p = fopen("input.csv", "r+");
if(p == NULL) {
puts("The file could not be opened");

[Code] ......

But lets say i dont know how many lines i have in my file and i want to count them and then use that size for my array so i tried this by:

int main() {
FILE *p;
int lines = 1;
char ch;
p = fopen("input.csv", "r+");
if(p == NULL) {

[Code] .....

But the second program is not working for unknown reasons. I do not get any errors but its not scanning the info because when i print the info later on it prints out random symbols.

View 11 Replies View Related

C/C++ :: Error In Scanning Database Names

Feb 13, 2014

I'm working on a program to store student's names, ID, and GPA, but for some reason the first and last name of the student are copied into every name of the database array once I scan them, regardless of whether or not add_student even runs.

typedef struct{
char *f_name;
char *l_name;
int stud_id;
double gpa;
} student_t;
int add_student(student_t db[], char fname[], char lname[], int iden, double grade, int db_size){
int i, error;

[Code] ....

For example, if I type "a Adam Johnson 1234 4.00" it'll add the first student with name Adam Johnson. However, if I try to add another student named "Kyle Walker", it overwrites "Adam Johnson" with "Kyle Walker" as soon as the names are scanned.

View 3 Replies View Related

C :: Scanning A File With Words And Int / Float Numbers

Dec 1, 2013

scanning a file with both words and INT's/Float numbers. This is the file data here.

15 25 200
3 10
17.99 22.99 109.99
100 2 4
5.99 99.99 20.00 49.99
10 10 10 10 10 10 10 10 10 10
3.99 5.99 7.99 8.00 5.00 5.00 5.00 6.00 7.00 9.99

[Code]...

What I'm focused on is reading in the first three numbers which I already have with fscanf and then reading in BUY TICKET with the digit afterwards. My problem is that I don't know how to reach that part of the file without scanning in something I don't want to. Also, how would I scan the number after scanning BUY TICKET? Would it be something like using %s and %d right afterwards?

View 4 Replies View Related

C :: Scanning 2 Dimensional Array For Duplicate Values

Mar 26, 2013

I am trying to scan a 2 dimensional array to see if there are any duplicates within a row or column; i.e. the concept of a sudoku game.how to scan a row or column one at a time.

View 1 Replies View Related

Visual C++ :: Pthreads - Solve System Of Equations By Gauss-Jordan Method

Dec 15, 2012

I have a problem: solve the system of equations by the Gauss-Jordan methods with pthreads. I have a big matrix A (for example 2000x2000), so i must solve Ax = b. Before I devide matrix to number of threads and each thread must work only with his peace of matrix.

Code:
#include <iostream>
#include "synchronize.h"
#include <pthread.h>
using namespace std;
typedef struct _ARGS {
int thread_count;
int thread_number;

[Code] .....

I write it on Ubuntu, and when I compile [g++ main.cpp -o main -lpthread -lm] the it works good(for example, if in 1 thread I get time_of_working = 10 sec, on 2 threads time_of_working = 5.4, i.e. about 2 times faster ), if I compile like this [g++ main.cpp -o main -lpthread -lm -O3] it is only 1.2-1.3 times faster.

View 1 Replies View Related

C++ :: Scanning A Header File To Save Image Data

Jun 11, 2013

I'm trying to read from a header file to take the image dimensions and other variables but I don't understand how to iterate through the "key" so it saves each line.

This is what the header file will always look like:

!INTERFILE :=
!imaging modality := nucmed
!version of keys := 3.3
;
!GENERAL DATA :=

[Code].....

Ideally it would just skip the keys that aren't wanted and keep moving through the lines. Should there be a for loop for the key (and if so, how does that work with pointers?) or should this method just be scratched...

View 6 Replies View Related

C :: Scanning Words Into Binary Search Tree - No Stack Error Diving Seg Fault

Apr 2, 2013

This is the first time I have encountered a "no stack." error giving me a seg fault. Anyhow, I am scanning words into a binary search tree and it is giving me a seg fault.

Here is the file (words.txt):
4
bravo
alpha
gamma
delta

Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

typedef struct node_t{
char *word;
struct node_t *left;
struct node_t *right;

[Code] .....

View 5 Replies View Related

C :: Multiple Functions Within A Program

Jan 22, 2013

I am getting an error on lines 31 and 36 about an expected identifier on my program that computes area and circumference. Is something wrong with my external functions outside of main?

Code:
#include <stdio.h>
#define PI 3.14159

double area;
double circum;

double find_circum (double radius);
double find_area (double radius);

[Code] ....

View 2 Replies View Related

C++ :: Functions - Declaring First And Defining Later In Program

Apr 6, 2013

I am looking at functions still and can't see the point in declaring the function at the top of the program, and then defining later i.e.

Code:
#include <iostream>
int add (int x, int y) {
return x + y;

[Code] .....

I obviously don't have much real world experience with this and am interested to see where declaring and defining later would be useful and/or beneficial.

View 14 Replies View Related

C :: Remove The Functions In A Program By Pre-processing

Jun 16, 2013

Is there a program that can remove the functions in a program by preprocessing

Code:

#include<stdio.h>
int is_even(int number);
int main(void)
{
if(is_even(number))
{
printf("%d is even", number);
}
}

[Code]...

To something like

Code:

#include<stdio.h>
int is_even(int number);
int main(void)
{
if( number%2 ==0 )
{
printf("%d is even", number);
}
}

I use the "-E" option when compiling with gcc on linux but its output still contains funcitons. Is there a preprocessing program that can remove functions from a program?

View 6 Replies View Related

C :: Program On Multiplication Of Matrices Using Functions

Feb 26, 2013

when i am running this program no errors are being shown but as soon as i press ctr+f9 to run the program my tc++ window closes.....

Code:
#include<stdio.h>
#include<conio.h>
void multiply(int m1[50][50],int ,int,int m2[50][50],int ,int );
void main() {
int i,j,m,n,p,q,m1[50][50],m2[50][50];

[Code] ....

View 4 Replies View Related

C++ :: Program To Check Validation Of Functions

Apr 12, 2013

I'm writing a program to check whether codes from a file are invalid, valid, inactive, or valid and active, but can't get it to work properly. The invalid codes are being found, but the other three are not. I think it may have something to do with my "active" function.

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
using namespace std;

struct ActiveCodes {
string code;
bool flag;

[Code] ....

View 19 Replies View Related

C++ :: Executing Multiple Functions In Program

Mar 24, 2013

We have been assigned to create a program that uses multiple functions. The professor has given us code for two of the functions, one to open a file and then another one to read the files contents and output them. I have put these into my program but they will not execute. The program does run, but the functions themselves are not executing. I have practiced with other functions that contain no parameters and those run fine, but the functions she gave us have multiple parameters.

The code I have so far is below:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
void PrintFile (string FileName, ifstream& inFile);
int main () {
ifstream inFile;
string fileName;

[Code] .....

View 1 Replies View Related







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