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
ADVERTISEMENT
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
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
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
Feb 8, 2013
There is no content when i search word in the dictionary.txt....this is my example of dictionary.txt...in the add case it is working,,only in search case...
--------------
dictionary.txt content.
--------------
mwet-asd.
test-test.
apple-prutas.
beryy-berry.
house-house.
--------------
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
int counter=0;
char op;
[Code] .....
View 1 Replies
View Related
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
Apr 1, 2014
i've been trying to figure out to search for a word in a text file and then display everything in the same row as the word found int ie this is whats in the file
john doe 3/21/1920 tech support review team 45,000
so user wants to find tech..and everything associated with it.
so program search for tech, when it does it then display the whole row.
john doe 3/21/1920 tech support review team 45,000
I can figure out how to search for a word, but no clue how to get it to then print out the row. This is all I can figure out to do.
ifstream FileSearch;
FileSearch.open("employee");
if(FileSearch.is_open())
{string letters;// search word would be store here
string row; ??stores entire row as string
while(1)
[Code]....
View 14 Replies
View Related
Nov 9, 2014
I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)
[Code] ....
Why my code does not fulfill it's purpose???
View 7 Replies
View Related
Mar 20, 2013
So basically here I have a menu in my C program and if I were to select option 2, I would enter a string up to 30 characters and it would output each block of 16 bytes should be shown which contains a character in the requested string. However, when I compile and run the program and search for the string, nothing happens. what I may be doing wrong?
Code:
else if (select == 2){
printf("Enter a string of up to 30 characters: ");
scanf("%s", &userstr);
//Compares both user's string and file string
for (i = 0; i < size; i++){
if (strcmp (buffer, userstr) !=0){
[Code]...
View 6 Replies
View Related
Mar 26, 2014
I'm new to program breadth first search and for my assignment we have to implement a breadth first search graph and output the order of the traversal. The problem is when I run my program I do not get any output from my traversal. All I get is "Breadth First Search Traversal starts at Vertex 2 and the order is: "
Here is my Queue class
//Declaration of node
struct node{
int info;
node *next;
};
//Defining Queue class
class Queue{
[Code] ....
View 4 Replies
View Related
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
View Related
Mar 7, 2013
I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.
#include <vector>
#include <queue>
std::vector<std::queue<int> > q
int min_index = 0;
task t // implemented in the other part of the program
[Code] ....
Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.
i need to do something like this
#include <vector>
#include <queue>
std::vector<std::queue<int> > q
task t // implemented in the other part of the program
while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue
[code].....
View 1 Replies
View Related
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
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
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
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
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
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
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
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
Sep 16, 2013
Write a program to find the number of comparisons using the binary search and sequential search algorithms
//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;
[code]....
View 4 Replies
View Related
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
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
Nov 2, 2013
I have a piece of code in C with header files included. I run it on Mac OS X Maverick with XCode 4.6.2 installed. GCC is also installed. Note that Command Line Tools in XCode are already installed.
When I compile it, the error I receive says something like this:
add.c:1:19: error: stdio.h: No such file or directory add.c:2:20: error: stdlib.h: No such file or directory add.c:3:20: error: unistd.h: No such file or directory
However when I run it on Ubuntu, it compiles without a problem.What to do?
View 2 Replies
View Related
Sep 10, 2013
I am working on a couple C++ projectsfor my class. On one of my projects I get this error "identifier not found" for maximumValue. here is the code that I have done. I have got almost all the code from my text book..
// Three numbers.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
// demonstrate maximum int value
int int1, int2, int3;
[Code] .....
View 5 Replies
View Related
Dec 7, 2014
I have counted my braces and it look to be correct but I am seeing double.. I am getting the "end of file found before the left brace.. do I have one in an incorrect place?
#include <iostream>
#include <string>
#include <fstream>
#include<cmath>
using namespace std;
int totalCaloriesBurned (double);
[Code] .....
View 6 Replies
View Related