C++ :: How To Search For The Value 80

Mar 29, 2013

i am having difficulties doing this program. i dont know how to search for the value 80.

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
class SortArray {
public:
int randomArray[];
int find(int randomArray[], int len, int seek);

[Code]...

View 1 Replies


ADVERTISEMENT

C++ :: Search And Find The Shortest Queue And Search After Some Condition?

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

C++ :: Binary Search And Sequential Search Algorithm

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

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++ :: How To Search For Certain Value

Mar 28, 2013

I am having difficulties doing this program. i dont know how to search for the value 80.

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
class SortArray {

[Code] ....

View 1 Replies View Related

C :: How To Do Search In Struct

Jul 9, 2014

So i create a simple structure,that has a firstname, lastname, age, dateofbirth.I would like it if i type what I am searching for print out there is one or not.But i have some trouble with equals(in array).. i type in the same "keresettnev" as "tanulok[i].Firstname" but it thinks not the same. (it works with age..)

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

struct student {
char *Firstname[40];
char *Lastname[40];
int age;

[Code] ....

View 12 Replies View Related

C++ :: Search For The Key Given A Content In Map?

Jan 7, 2014

In a C++ map, is there any way to search for the key given a content? Example:

I have this map:

map<int,string> myMap;
myMap[0] = "foo";

Is there any way that I can find the corresponding int, given the value "foo"?

cout << myMap.some_function("foo") <<endl;

Output: 0

View 3 Replies View Related

C++ :: How To Correct The Search In The End Of Program

Jun 1, 2013

Code:
#include<conio.h>#include<iostream.h>
class air_line {
private:
char name[5][100],name1;
long double opt,opt1,opt2,cnic[5],ticket_number[5],ticket_number1,cnic1;
public:
void input()

[code].....

View 1 Replies View Related

C++ :: Search Binary Tree

Aug 12, 2014

It has been a while since I built a binary tree from scratch so I decided to do it. Everything works fine but this one function. When I enter a number to search it just keeps running and allowing me to keep enter numbers.

Code:
void tree::search(int key,Node* leaf) {
if (leaf == NULL) {
std::cout<<"The tree is empty

[Code] ......

View 3 Replies View Related

C :: Depth-first Search Of A Graph

May 18, 2013

You have to implement a data structure to represent graphs,directed or undirected,that tries to avoid the wasted space in the representation of a graph with adjacency matrix and the difficulty of searching the edges with adjacency list representation.We consider that the vertices are numbered from 1 to nverts and the exit degree of each vertex is at most MAXDEG. If deg[i] is the exit degree of the vertex i then the neighbors of the vertex i can be saved at the matrix edge[i][j], 1<=j<=deg[i].

Write a program that reads the datas from a file: if the graph is directed or undirected(1 or 0), the number of vertices (nverts),the number of edges (nedges) and the first and the last vertex of each edge.Write the function dfs that, with argument the data structure that you implemented before for the representation of a graph, prints the edges by the depth-first search of a graph. What I've done so far is: I wrote a program that reads these information from a file, calculates the exit degree of each vertex and creates the matrix edge[i][j]. What data structure do I have to implement???

View 1 Replies View Related

C :: Linked List Search

May 7, 2013

I read an article on linked list here: C Linked List Data Structure Explained with an Example C Program

Code:

struct test_struct* search_in_list(int val, struct test_struct **prev)
{
struct test_struct *ptr = head;
struct test_struct *tmp = NULL;
bool found = false;
}

[code].....

What is "if(prev)"? Wouldn't "prev" always have the same value? Secondly, if tmp is NULL (which will be the case when the loop if(ptr->val == val) finds a match the first time it is run), is *prev assigned a NULL?

View 1 Replies View Related

C :: Search File For String

Aug 22, 2014

I should state that I am recently new to C programming. I have dabbled with Python in the past, but nothing formal. I am taking a C programming class, but it is an introductory course. As such, the instructor is moving extremely slow through the material.

With this program, I am trying to search a given text file (line-by-line) for user-submitted data. I then want to be able to store which line that data was found on. The program runs, but it always results in "Sorry, couldn't find a match." Even if it shouldn't.

Code:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
}

[code]...

I should probably explain my overall goal with this program.I would like to write a program that will calculate the molecular weight of a compound. I expect the user entered molecular compound to be something like this: CH3COOH (An equivalent entry could be C2H4O2)Also, it needs to be case sensitive because the chemical formulas are case sensitive.

The output will be "The molecular weight of CH3COOH is xxx.xxxxx grams".I have two text files as well. One contains a list of all chemical symbols, and the second is a list of all atomic weights in the same order as the first. I want to place the user inputted data into an array, then search for each element of that array in the chemical symbol text file. It will show which line it was found on, then I can use that line to grab the atomic weight from the second text file.

View 5 Replies View Related

C :: How To Search For Record And Deletes It

Apr 9, 2013

I am trying to get my program to search for the account ID in the structure and deletes the record as the account ID is found. The problem is that my codes are not working. (since my whole program is too long, I only show a part of it.) Here are my codes:

Code:

#include <stdio.h>
#include <string.h>
struct Account
{
char* Account_ID;
char* AccountOwner_FirstName;
char* AccountOwner_LastName;
}

[code]....

View 4 Replies View Related

C :: Depth First Search Implementation

Mar 12, 2013

I'm having problems with implementing depth first search.

Code:
6 10 //6vertices 10edges
0 2 //vertex and its adjacent vertex
1 0
1 2
2 3
2 4
3 1
4 1
4 3
4 5
5 3

Output to terminal: 0 2 3 1 4 5
but it should be: 0 2 4 5 3 1

Here's my code:

#include<stdio.h>
#include<assert.h>
/* maxVertices represents maximum number of vertices that can be present in the graph. */
#define maxVertices 100
void Dfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)

[Code] ....

View 1 Replies View Related

C :: Search Chain In String

Mar 23, 2013

i have a work to do that consists on a given char pointer to a chain and a also given char pointer to a string. i have to search that chain in the string, and return the position where the beginning of the two it's equal. but only if they are equal.

example: string is "abcd" and the chain is "bc". want to find the chain, and if it exists, the position return will be 2. in the work it says that we should use sprintf() too. here is my code, which is incomplet yet.

Code:

char* pos(char* C,char* S){
char *str = S;
char *chain = C;
int i, j, temp;
int lengthStr = strlength(C);
int lengthChain = strlength(S);
}

[code]....

my doubt is how to use sprintf() and where. if i have to use malloc() and free(),

other examples:
pos(AGA,CTGCA)
return:
0

pos(AGA, ATAGATA)
return:
3

pos(AGA AGATAGA)
return
1 5

View 6 Replies View Related

C++ :: Cannot Search Words From Input

Apr 14, 2013

i am trying to create a c++ program that asks for an input and determines if it is a question or not by searching each word from the input across a database (txtfile)..so far I have managed to make it search the database for the word but it only works on one word.... i would like to be able for it to search every word on the input separatly..here is the code:

#include <cstdlib>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[code]....

View 4 Replies View Related

C++ :: How To Search For An Item In The Array

Jun 29, 2014

If the item is in the array. Count how many times it is stored in the array and what are their respective array locations.

How can I add this output in my program.

Here's my code...

int array[15]={28,3,16,4,3,16,5,8,4,12,5,4,8,21,40};
int x=0;
int done=0;
int item;

cout<<"Input an item to be searched:";
cin>>item;

[Code] ....

This should be the output:

Item to be searched: 4
number of occurence : 3
array locations : 3 8 11

View 3 Replies View Related

C++ :: How To Search For A Substring In A File

Jan 12, 2013

How I can search a sub string in a file? Length of sub string is Variable and the number of search is indefinite.

View 15 Replies View Related

C++ :: Functions Doing A Word Search

Nov 5, 2013

I am writing a program that determines how many times a word is repeated in a file without a main function. I almost have it correct but it doesn't exit after it finds how many of the last word and it just loops.

Here is my coding

int count_the_word(string filename, string word) {
ifstream word_search;
int number_the = 0
int number_is = 0
int number_of_romeos = 0
int number_case = 0
string user_input;

[Code] ....

there is also two more lines from a different txt file i just havn't coded them yet.

the main function that is used to test it is as follows
cout << count_the_word("raj.txt", "the") << endl;
cout << count_the_word("raj.txt", "is") << endl;
cout << count_the_word("raj.txt", "Romeo") << endl;
cout << count_the_word("raj.txt", "case") << endl;

it works like its supposed to but like i earlier mentioned it outputs another number after it finds how many "case" are in the file and then it loops asking for a filename.

View 2 Replies View Related

C++ :: DLL Search Directory Order

Aug 29, 2013

I was working on a program. "hey if this program were to be published it would be bad for people to see all dll files are in the exe directory"....

So I wondered if there is a way to make compiler see a folder in the same directory with exe file which holds all dll files?

Also look at some programs and saw they have a dll folder which holds dll files....

View 1 Replies View Related

C++ :: Search For A Character From The Phrase

Aug 18, 2013

When the user selected this option, your program should be able to accept a character from the user and search for this character from the phrase. Your program should be able to identify the location of the character in the phrase. I've try the arrays but still can't go .....

View 16 Replies View Related

C++ ::  Depth First Search - Won't Compile

Jan 13, 2013

I've been trying to implement this Depth First Search graph algorithm using STL, and I get some error from Visual C++ 2012 at compilation.

The code is:

#include <fstream>
#include <stack>
#include <vector>
#include <algorithm>

[Code].....

And the error says something like this:

Debug Assertion Failed!

Program: C:WindowsSYSTEM32MSVCP110D.dll
File: d:...vs2012vcincludedeque
Line: 1497

Expression: deque empty before pop

View 1 Replies View Related

C++ :: File Info Search?

Feb 27, 2013

I am looking for a way that I could check the information of a folder and a drive, to show the data size and storage amount (KB, MB, GB). This is so that I can compare the size of a folder to the storage capacity of a disk drive.

View 2 Replies View Related

C/C++ :: MPI Prime Number Search?

Mar 14, 2015

We are working on building a cluster and needed to create or find a program writen in C that we can run. I was thinking a program that finds prime numbers and insert them into a MySQL database. I have never worked with C so I don't know where to start or anything. I have a week to prove our project is worth keeping and our cluster is almost completely installed we just need to create a program.

View 4 Replies View Related

C/C++ :: NNS Search Using Sum Of Squared Differences

Aug 7, 2014

I'm trying to get a project for an assignment. I have got it nearly working but the final result is completely erroneous. We are given two text files. One that has a noise image. This needs translating into a binary image. Which is quite easily. Using a threshold I just cycle through a loaded text file with a threshold and it refines the image perfectly. Then it saves fine. Obvious with this being a binary image it saves it as values of 1 and 0. However, the other text file is a shuffled image in set block sizes (512 x512 image into blocks of 32x32) with values of 0 or 255 for each cell.

So I set the cell values of 1 to 255 and 0 remain the same. Here is where I have the problem. My solution has to use a Nearest Neighbour search using Sum of Squared Differences. I have constructed a solution that should work on paper but it gives me a completely erroneous output for the solution to the second image.

My solution is to go by each block X and Y (512/32 = 16 x and 16 Y blocks) of the binary image(allmost perfect normal image) and for each one find the lowest SSD score and set the solution as it. Then goto the next block and repeat. Here is a copy of some of my code.

.H info

class Matrix {
int M, N;// No of rows and columns
public:
Matrix(int sizeR, int sizeC, double* input_data);
Matrix();// default constructor for empty type
Matrix(int asizeR, int sizeC);
double get(int i, int j)const;

[Code]....

It then writes to file. I excluded the binary image as I know that is all correct.

View 10 Replies View Related

C/C++ :: NNS Search Using Sum Of Squared Differences?

Aug 7, 2014

I'm trying to get a project for an assignment. I have got it nearly working but the final result is completely erroneous.

We are given two text files. One that has a noise image. This needs translating into a binary image. Which is quite easily. Using a threshold I just cycle through a loaded text file with a threshold and it refines the image perfectly. Then it saves fine. Obvious with this being a binary image it saves it as values of 1 and 0. However, the other text file is a shuffled image in set block sizes (512 x512 image into blocks of 32x32) with values of 0 or 255 for each cell.

So I set the cell values of 1 to 255 and 0 remain the same. Here is where I have the problem. My solution has to use a Nearest Neighbour search using Sum of Squared Differences. I have constructed a solution that should work on paper but it gives me a completely erroneous output for the solution to the second image.

My solution is to go by each block X and Y (512/32 = 16 x and 16 Y blocks) of the binary image(allmost perfect normal image) and for each one find the lowest SSD score and set the solution as it. Then goto the next block and repeat. Here is a copy of some of my code.

.H info

class Matrix {
int M, N;// No of rows and columns
public:
Matrix(int sizeR, int sizeC, double* input_data);
Matrix();// default constructor for empty type
Matrix(int asizeR, int sizeC);
double get(int i, int j)const;
~Matrix();

[code].....

View 1 Replies View Related







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