C++ :: Linear And Binary Summation?

Feb 6, 2015

I am trying to write a program that will output the contents of an array A into a sum hence title.

Here is my code so far...

#include <iostream>
using namespace std;
int LinearSum(int A[], int);

[Code]....

View 1 Replies


ADVERTISEMENT

C/C++ :: Binary And Linear Search Program

Mar 30, 2014

// ***This program uses a binary search and a linear search to see if a 3-digit lottery number matches the number on any of the player's tickets.***//

#include <iostream>
using namespace std;

[Code].....

bunch of errors and completely lost. what it's supposed to look like.

View 4 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.

How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C++ :: Adding Two Floats - Summation?

Jun 27, 2013

I am very new at c++ and ran into this problem.

pairPercentage = ((float)tempPair/hands) * 100;
flushPercentage = ((float)tempFlush/hands) * 100;
totalPairPercentage = pairPercentage + totalPairPercentage;

is there something I should be awarded of when adding two float(s) ? because totalPairPercentage will always return pairPercentage, not its summation.

also did (totalPairPercentage += pairPercentage);

View 3 Replies View Related

C++ :: Comparing Execution Times Of Summation

Mar 17, 2014

This is the problem:

1+2+3+...+n=(n(n+1))/2

Write a C++ program that compares the execution time of the above summation using two different solutions: one that uses loops, and another that uses the closed form approach. Use large values of n for the comparisons, such as, 10^7, 10^8, 10^9, 10^10, 10^11,10^12, 10^13, and 10^14. Provide a comparison table for the execution time in both solutions.Do not worry about the value of the actual sum. Overflow will occur in the sum value rendering it invalid; however, this is not the primary concern of the program. Execution time is the primary concern.

View 1 Replies View Related

C++ :: Summation Of Numbers In Current And Previous Iterator

Jul 9, 2012

Below is the sample of the code :

int summation = 0;
for (it= s.begin(); it!= s.end(); ++it) {
summation += std::atoi( ((*it).substr( 8 )).c_str() );
}

Nos after the first 8 characters are the ones I need to perform addition on.

do the summation of these nos.

View 14 Replies View Related

C :: Running Linear Actuator Without Feedback

Jan 4, 2014

I am trying to do single axis solar tracker with linear actuator /rtc/ UNO. I have already done with feedback sensor.

Now Here I am trying to without feedback. Linear actuator specification: 24v , 3.2mm/sec as speed , 600mm stoke.

Desired angle calculation:
tracking start from 7am to 18PM, 11hours
Assumed degree: 7AM as -45 deg , 12.30 as 0 degree and 18 pm as 45 degree.
static float slope= 0.00227272727273;
static float intercept=- 102.272727273;

[Code] ....

How can i put time here. Coding for calculating Ton time and solve above equation. below i posted my code . I need it has to be modified little bit. i need to implement ton time actuator here.

I need function takes desired and actual angle , where actuator try to move to its actual desired position.

Code below in arduino version

Code:
double Desire_Degree;
unsigned int TS;
static float slope= 0.00227272727273;
static float intercept=- 102.272727273;
static int length;
double Actual_Degree;

[Code] .....

View 1 Replies View Related

C++ :: Merging Sets In Linear Time

Jan 5, 2014

I have two std::sets S1 and S2 which I need to merge.

I know that the largest element of S1 is less than the smallest element of S2.

the additional information about S1 and S2 should enable me to do the insertion of each element in costant time instead of log(N).

what is the fastest way to calculate the union of the two sets?

View 6 Replies View Related

C/C++ :: Continuous Linear Linked List

Feb 11, 2015

I'm trying to write a continuous linear linked list. But whenever I run my program and enter an option from my list, my switch statement gets highlighted in green and says "Thread 1: breakpoint 3.1. And then my program just stops. I'm wondering what part of the switch statement I've gotten wrong.

Here's my code.
#include <iostream>
using namespace std;
struct node
{
int key; node *next; };
node *l;
void print(node*list)

[Code] .....

View 13 Replies View Related

C/C++ :: Linear Search Not Found Output

Jul 3, 2014

How to return a message saying that the value searched for is not found. We had to pull the data in from a .dat, i won't let me attach it as a .dat so I attached it as .txt. I know my it's sloppy. I usually clean up what I can once it is working properly.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int ccnt;
int size = 10;

[Code] ....

Attached File(s) : dat45.txt (273bytes)

View 3 Replies View Related

C++ :: Implementation Of Linear Programming Solver

Sep 17, 2013

I am trying to implement the linear programming solver. This is the header file of the linear programming solver :

/*!
internal
Representation of a LP constraint like:
(c1 * X1) + (c2 * X2) + ... = K
or <= K
or >= K
Where (ci, Xi) are the pairs in "variables" and K the real "constant".
*/

[Code] .....

I want to parse all the constraints and bounds as inputs and get the maximum value of the objective function as the output using the above lpsolver header file. I have also attached the sample file below.

View 14 Replies View Related

C++ :: Linear Searching Through Array Of Class Objects

Jan 22, 2013

I have a linear search algorithm set up to search through an array of class objects it works but the output does not match, when i search for a particluar name in the array the 1st and third values int the array are found but the second value is not found..

below is my code:

int linsearch(string val) {
for (int j=0; j <= 3; j++) {
if (player[j].getLastName()==val)
return j ;

[Code] .....

View 2 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++ :: Data Fitting Routines (Sinus Or Linear Fit)

Feb 5, 2014

Looking for data fitting routines?

I want to fit datapoints with a sinus or with a linear fit.

View 3 Replies View Related

C++ ::  Linear Linked List Traversal Broken

Nov 16, 2014

I'm attempting to insert items in my list in sorted order. I have accounted for if head is NULL, and if the item I'm trying to insert is less than head. But the problem occurs when I try to loop through until I find the item that is less than what I want to insert. In the while loop, the program just stops for some reason. Here is my code:

else if(strcmp(temp->aPerson.firstName, head->aPerson.firstName) == 1) {
node * previous = head;
node * current = head->next;

[Code] ....

I'm not accessing memory that's not mine, I've made sure that current->next is a real node. I've been troubleshooting this for a couple of days, and I don't understand because it won't even get to the assigning part. It just stops after it goes through the while loop once, it won't go any further, no matter how many items I have in the list.

View 2 Replies View Related

C :: Linear Search Function Accessing String In A Struct?

Apr 5, 2013

I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.

My problem is accessing the array to search through.

Here is my code:

Code:
#include "stdio.h"
const int IDLEN=30; //All constant values defined
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
//First structure defined
struct TransistorRec {

[Code]......

The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'

View 11 Replies View Related

C++ :: Linear Interpolation Code For X And Y Axis - Compile Errors

Oct 15, 2012

When trying to compile, I am receiving errors which I am assuming are pretty generic and common:

lin_interp.c:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
lin_interp.c:100: error: expected '{' at end of input

I am just trying to get the code to work for now. I have created a program similar to this which worked in C++, but the code isn't jiving in C.

Code:
// Lin_Interp.c : Defines the entry point for the console application.
//
#include "PACRXPlc.h" /* Include file applicable for all targets */
#include "ctkInitCBlock.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#include <time.h>
#include <ctype.h>
#include <stdio.h>
/* Constants / #defines */
// Print-Out on console "XY LIMIT ARRAY" XYlim

[Code] .....

View 8 Replies View Related

Visual C++ :: Linear Program For Matrices - System Cannot Find Path Specified

Dec 8, 2012

I have two pieces of code:

Code:
#include <cmath>;
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>

[Code] ....

I am using the gnu glpk library to calculate a linear program for my matrices. Why I get the error message exit code 3 which apparently means "The system cannot find the path specified"?

View 12 Replies View Related

C++ :: Insert Numbers Into A Hash Table Of Size 10 - Using Linear Probing And Chaining

May 28, 2014

How to approach this? Not very clear on how hashing works..

Insert the following numbers into a hash table of size 10 (ie an array with 0…9 index position) using a hash function h(k)=(k*71+94)%10 and using Linear Probing.

75, 98, 43,1,-56,93,101,34,23

Insert the following numbers into a hash table of size 10 (ie an array with 0…9 index position) using a hash function h(k)=(k*71+94)%10 and using Chaining.

75, 98, 43,1,-56,93,101,34,23

View 2 Replies View Related

C :: Linear Search Script - Calling Array Inside Of User Defined Function?

Jul 24, 2013

im tasked with creating a linear search script using functions on a 10 element array. the elements are to be supplied by the user as is the search target.

I understand how to create the array and gather that information from the user as well as howto set a variable for "target", this is what im calling it. Those two parts are simple enough.

I am not fully understanding the calling of an array in a function as a pointer. i semi understand the use of a pointer and howto call a normal pointer in a function. i also understand that an array is nothing more then a "special" pointer with a set of consecutive address blocks for the size of the array.

My first user defined function is simple enough

Code:
ReadArray(int A[], int size){
int i;
printf("Please enter %d integer numbers separated by spaces:
", size);
for (i = 0; i < size; i++)
scanf("%d", &A[i]);
}

Sso nothing out of the ordinary there. that should be a standard for loop and use of scanf, sadly prof has not covered ssanf or any of the other options so i am stuck using scanf for now. maybe someday down the line in a other program or after this course ill get the chance to learn about better options for gathering data from the user.

I am confused as to my next function:

Code:
void SearchArray(int A[], int target, int size);

I've not written any code here yet as im not sure if i should call the A[], or *A for the first type of the function?

If i call *A do i then use something like this for my search:

Code:
for (*A = 0; *A < size; *A++)
if (*A < target) or use A[] insteadA?

Code:
for (i = 0; i < size; i++)
if (A[i] = target)

View 6 Replies View Related

C++ :: Linear Buffer Coordinate - Printing Onto Screen Coordinate

Mar 24, 2013

I have a linear buffer coordinate, i am to print onto a screen coordinate.

Say maxy = 20, maxx = 10, bufferx = 20, y, x,
Buffer coordinates to screen coordinates:
Algorithm: So for each maxx'th of bufferx, y will +1 and x will reset.
Mathematical: y = int bufferx / maxx,
const double averageIncr = int (maxx+1/maxx) - double (maxx+1/maxx);
So the amount of averageIncr in (int bufferx / maxx - float bufferx / maxx)
is the screen x coordinate. Then
(int bufferx / maxx - float bufferx / maxx) / averageIncr = x

Screen coordinates to buffer coordinates:
bufferx, y = 21, x = 10, maxy = 20, maxx = 10,

y * x would be the case if bufferx <= max screen coordinate.
There is no max bufferx.

How to find the transition from screen coordinates to buffer coordinates? Also, if the algorithm within a for loop, or that the mathematical way would be slower or not? I rarely touch floating point stuff.

View 3 Replies View Related

C++ :: Non-restricted And Restricted Linear Data Structure

Feb 9, 2013

Can linear and non linear data structure can be used together in a program...

View 4 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C++ :: Error With Binary IO

Jan 6, 2015

I am trying to make a program like a virtual machine, and therefore I need to have a virtual hard drive. I have it split across four files, each being exactly 67,108,864 bytes (at this point, the files consist of 0x00 throughout the entire file). When I try to write to the beginning of one of the files, I get a "EXC_BAD_ACCESS (code=1, address=0xff)" from Xcode.

Here is my source code.

Code: #include <iostream>
#include <fstream>
using namespace std;
int main()
{
fstream drive1("main1.vhd", ios::in | ios::out | ios::binary);
fstream drive2("main2.vhd", ios::in | ios::out | ios::binary);
fstream drive3("main3.vhd", ios::in | ios::out | ios::binary);
fstream drive4("main4.vhd", ios::in | ios::out | ios::binary);

[code]....

View 4 Replies View Related

C :: How To Manipulate Binary

Oct 5, 2013

My assignment is to write a binary calculator that works with floating point for simple math (+,-,x,/). How to do this. the binary numbers need to be from the user.

View 2 Replies View Related

C++ :: Printing A Binary Tree?

Feb 1, 2014

It only prints out the root in an infinite loop.

Code: void Btree::printTree(Node* tree)
{
tree=root;
if (tree != NULL)
{
std::cout<<" "<< tree->key;
printTree(tree->left);
printTree(tree->right);
}
}

View 5 Replies View Related







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