C/C++ :: Sorting And Searching Two Arrays (int / String)

Apr 2, 2014

Write a function to read and display the contents of names and marks. You then ask the user for a name and using the linear search return the index to the user. If -1 is returned then the name is not in the file. Otherwise write out the name and mark for that student.

Next, sort the arrays, write them out and then ask the user for a name to search for. This time use the binarySearch to return -1 or an index. Display the student's name and mark if found.

void getNames(ifstream& inStream, string names[], int marks[], int numElts);
int linearSearch(const string names[], int numElts,string who);
int binarySearch(const string names[], int numElts,string who);
void selectionSort(string names[], int marks[],int numElts);
void displayData(const string names[], const int marks[], int numElts);
[Code] ....

Now I have worked up some stuff in parts but I am so lost and confused with these specific requirements: Previous questions asked me to sort out a linear search, a binary search and

LINEAR SEARCH:

int searchList(int list[], int numElems, int value) {
int index = 0; // Used as a subscript to search array
int position = -1; // To record position of search value
bool found = false; // Flag to indicate if value was found

[Code] ....

View 3 Replies


ADVERTISEMENT

C/C++ :: Sorting 10 Names And Searching For One

Mar 5, 2015

So I been asked to write a program that does the following:

Write a program that allows the user to enter a series of 10 names from the keyboard and then sorts and prints the names in alphabetical order. Use a series of functions:

1) Input the data
2) Sort the data (use a bubble sort)
3) Print the data

After this is done, allow the user to enter a name from the keyboard and determine if the name appears in the list. Use a function to accomplish the search. The name to be searched for should be input within main and sent to the function as an argument.

4) Search the data (use a binary search of type bool)"

this is whats I wrote so far and its giving me error with the sorting and the searching, I need to fix it and I cannot figure out how?!.

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void bubbleSort(string[], int);
int main()

[Code]....

View 3 Replies View Related

C++ :: Sorting And Searching With Bubble Sort?

May 15, 2014

I'll make a program that consists of "sorting and searching." To cope with the task, it should contain this: Create a field containing 50 random numbers, sort them by a method sort according to Bubble sort and then out the field before and after sorting. [URL]

View 1 Replies View Related

C++ :: Searching Files For A String

Jan 30, 2013

I have 80,675 Files, 8,213 SubFolders.

I would like to search each file for a string, which will be last name.

Matches string, outputs path/filename, either to screen or a output file.

I have done this to a single file but never to multiple files and folders.

View 2 Replies View Related

C++ :: Searching For Character In String

Jun 19, 2013

I'm trying to find a < character in a document, get it's position. Then find > and get it's position. Then i want to delete all things between that but runtime is terminating my process so i don't know what to do.

The code:

#include <iostream>
#include <conio.h>
#include <stdio.h>

[Code].....

View 6 Replies View Related

C++ :: Searching String Within Vector Struct

Nov 3, 2013

New to C++ lambda, got two question in regards of searching for strings within a vector struct.

Minimalistic example:
Code:
struct singleFile {
std::string filename;
};

std::vector<singleFile>myStorage;
myStorage.push_back(singleFile());

[Code] ....

1) why does found always return 0 eventhough the filename exists?

2) I don't know how to pass an actual search string instead of the hardcoded approach as above with filename =="

View 6 Replies View Related

C :: Searching A String On Char Matrix

Apr 12, 2014

I want to make a program that receives the number of lines and collumns of a matrix, a matrix of char, the number of pairs of coordinates and the coordinates. the program has to return the char (or chars) that are on those coordinates on the matrix.

Example:

receives
2 3 ABC DEF 2 1 1 1 2

returns

AB

this is how i tried to solve this problem:

Code:
#include
#define MAX 1000
int main() {
int nlin, ncol;
char mat[MAX][MAX];
int x[MAX], y[MAX];
int ncoords;
int l, c, n;

/* receiving variables and storing matrix.*/

[Code] .....

For some reason that i can't seem to find, this solution is not right.

View 6 Replies View Related

Visual C++ :: Searching File For String?

Nov 8, 2012

The program then asks the user for a search string, which may contain white space. The program should search the file for every occurrence of the search string. When the string is found, the line that contains it should be displayed in the following format

nnnnn:Line Contents

That is the line number of the line, 5 columns wide, right justified, followed by a colon, followed by the contents of the line.

And this is what I've got so far:

Code:
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
using namespace std;
int main(int argc, char *argv[]) {
ifstream inFile;
string fileName,

[code]....

But this doesn't work. It prints everything in the file, not just the lines where the string is found.

View 9 Replies View Related

C++ :: Searching Through Entire String Looking For Spaces / Punctuation

Dec 11, 2014

I have it searching through the entire string letter by letter, looking for spaces, punctuation, etc... yet it still is continuing on with the space.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdio.h>
#include <cctype>
#include <algorithm>

[Code] ....

Output:
if(str_word == " ")
//or
if(str_word == ' ')

It does nothing to change it. I am completely baffled.

View 4 Replies View Related

C++ :: Sorting 2 Corresponding Arrays?

Nov 21, 2013

I am trying sort my Calorie array and day array corresponding to each other but how to start i cant grasp the concept for some reason. I want it to sort by calories in descending order.

So instead of this...

Day: Calories:

1 200
2 500
3 400
4 600
5 100

I want this.....

5 100
1 200
3 400
2 500
4 600

#include <cstdlib>
#include <iostream>
using namespace std;
//Prototypes
int getDays(int);
void getCal(int*,int);
float calcSum(float,int*,int);

[Code] ....

View 1 Replies View Related

C++ :: Sorting Integers Without Arrays?

Jan 29, 2015

I have been tasked with sorting a text file with some numbers in it. For example, there can be 5 numbers in it: 1,2,3, 4, and 5. However, they are out of order (3,2,4,1 and 5). I need the numbers in numerical order. How can you sort the numbers into a new file?

Bubblesorting? I can not use arrays in this program. I have already determined the minimum number in the file.

View 5 Replies View Related

C++ :: Sorting Two Arrays Of Structures?

Mar 26, 2013

I wanted to sort two structure-arrays according to their element values and get their indices changed accordingly.For example if my array is

A[]= { 2 4 1 8 6}
indices[]={ 1 2 3 4 5}

then after sorting it should become

A[]= { 1 2 4 6 8}
indices[]={ 3 1 2 5 4}

I tried implementing it using the following code but I failed to get correct output.

Code:

#include<iostream>
#include<cstdio>
using namespace std;
#define inf 100000
struct array
{
int x;
int y;
};

[code]....

View 4 Replies View Related

C/C++ :: Sorting And Indexing Arrays?

Apr 22, 2014

I am trying to create a program that will read data from a text file into a string. Afterwards I need to sort the data in ascending order and print it. So far my program reads the data but I'm not sure how to go about indexing the array.

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

[Code].....

View 3 Replies View Related

C/C++ :: Counting And Sorting Arrays?

Nov 7, 2014

I'm trying to write a program that should output, in a tabular form, the name of the algorithm, size of the array, number of comparisons and number of swaps. I am really, really, really bad at arrays and comprehending how to output variables from several. Especially in tabular form />

Here is what I have written thus far:

#include <stdio.h>
#include <stdlib.h>
#define MAX_ARY_SIZE 10

[Code]......

My questions:
1 - How do I make the array size change from 10 to 100 to 1000?
2 - How do I populate the array's with random non-repeating numbers?
3 - How do I make each algorithm count the # of comparisons and swaps?
4 - How do I return the counted comparisons AND swaps (in one return function??) and then print them?

View 6 Replies View Related

C :: Print Two Arrays On Same Table After Sorting

Jul 11, 2013

Having trouble with homework involving (title). Here is the assignment:Write a program that allows the user to enter 10 numbers from the keyboard. Sort the numbers using any sort routine you wish. The output from your program should be 2 columns of numbers. The left column should be the numbers in the order they were originally entered and the right column should be the sorted list. The columns should be labeled. You will need 2 arrays to accomplish this.

Use separate functions for input, sorting, and printing.So, I have to use separate functions for each of these. I would think it would be easiest to do the input in Main() and then the sorting and printing in another function, but of course since you can't return arrays I am kind of stuck on how I return the new array after sorting. I thought about doing the sorting in Main(), but then I would need to still do the original arrays input in a function and would still run into the same problem.

Here is what I have so far:

Code:

//Cameron Taylor
#include <stdio.h>
#define MAXARRAY 10
int highLow(int[], int);
int print(int[], int[], int);
int main (){
int unsorted[MAXARRAY], i, j, temp;

[Code]...

I know it seems simplistic right now, but I am just trying to get it to work first and then go back and beautify it up a bit.

View 9 Replies View Related

C++ :: Merging Arrays And Sorting The Resultant

Jan 10, 2015

Write a program using user-defined function to merge the contents of two sorted arrays A & B into third array C. Assuming array A is sorted in ascending order, B is sorted in descending order, the resultant array is required to be in ascending order.

View 1 Replies View Related

C++ :: Sorting Arrays In Ascending Order

May 28, 2014

// OK this program outputs an array of numbers which are read from two .txt //files which are set1 and set2.

// set1.txt has: 8 37 29 31 40 25 18 38 4 45 34 39 12 21 24 3 5 23 26 44

// set2.txt has: 46 42 25 20 19 29 49 4 32 2 10 12 39 17 33 6 3 15 45 21

// But the problem is that when you run the program, the numbers do not come out // in numerical order.

#include <iostream>
#include <fstream>
#include <string>

[Code]....

View 2 Replies View Related

Visual C++ :: Sorting Parallel Arrays?

Apr 4, 2014

Class programming project where we declare two arrays, a sting array containing the names of the boroughs and an int array which which holds accident number for each borough. The main function calls getNumAccidents() function to fill the array. it then calls findLowest() to learn which borough had the fewest accidents. It should print out the accident numbers for each borough and then out the borough and accident number with the fewest accidents.

I'm able to get the program to kind of work. When I run it everything works fine but I am not able to get the arrays to sort and match up correctly..

#include<iostream>
#include<iomanip>
#include<string>
#include<cstring>
using namespace std;
class combineSort {
public:
combineSort() {

[code]...

View 14 Replies View Related

C++ :: Sorting Arrays - Int Numbers From Highest To Lowest

Oct 29, 2014

For my program i need to sort my int numbers [5] from highest to lowest but it seems that i made it go from lowest to highest ...

Code:

#include <iostream>
using namespace std;
int main() {
int numbers[5] = {3, -6, 10, 1, 130};
int counter1, counter2, tempNum;
//Highest to Lowest

[Code] ....

View 1 Replies View Related

C :: Sorting Arrays Of Pointers - Assigning Data To Gene

Feb 11, 2013

Code:
typedef struct {
name_t name;
float beta[beta_num];
} gene_t;

[Code] ....

Is gene an array of address ? How come the compare function doesn't work ?

View 1 Replies View Related

C/C++ :: Quick Sorting Arrays Created With Random Integers

Feb 9, 2014

I am having some problem with my quick sort problem. My program is supposed to create 5 arrays with 5,10,15,and 20 random integers, respectively. Then it should sort those arrays, where the numbers are bigger or smaller than the middle element in the original array! The program I wrote should do that but, its not! The program just keeps running infinitely!

#include <iostream>
#include <cstdlib>
using namespace std;
void p(int k[],int left, int right) {
int i = left, j = right;

[Code] ....

View 8 Replies View Related

C++ :: Sorting Strings / Arrays In A User Defined Lexical Order?

May 7, 2013

I previously tried to put strings in an array, but i couldn't modify the first index in the string that is in the array. I changed my code later.

[URL]

Suggest a function that sorts the inputs vertically according to the order given by the user? I made this one

void order(string order, char index[][15]){
int counter=0,line=0,i=0,j=0;
for(i=0;i<=15-1;i++)
{for(j=0;j<=15-1;j++) {
if(index[j][i]==order[counter])

[code].....

View 1 Replies View Related

C/C++ :: Sorting String From A File?

Mar 23, 2015

I am writing a code that is supposed to read a resistor code and determine the resistance nominal, lower, and upper and write those numbers to a file in various ways. I already accomplished writing to the file output and the file nominal but now I have to sort the file nominal by the nominal readings. I managed to tokenize the string so I could read the second part of the string .....

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
double bandNum(char x);
double bandMult(char x);
double bandTol(char x);
int main() {
FILE *pFile;
FILE *pFileOutput;

[code]....

View 4 Replies View Related

C++ :: Sorting String Array Alphabetically

Nov 7, 2014

I wish to sort a string array alphabetically and im not sure if i am doing it right. for example:

string a[5]; //initial array
string b[5]; //sorted array
int index = 0; //index of b array

for (int i = 0; i < 5; i++){
for (int j = 0; j < 5; j++){
int c = 0;

[Code] ....

View 2 Replies View Related

C :: Sorting Number As A String By Ascending Order

Jul 2, 2014

make my program sort data.in this case number that i declared as char(not string, my bada)if i have

name1
number 2500
email

name 2
number 2400
email

i need to put that this way:
name 2
number 2400
email

name1
number 2500
email

i saw that can be done with qsort but when i try it it doesn't work.

Code:

typedef struct {
char nome[MAX_GERAL], email[MAX_GERAL], morada[MAX_GERAL], postal[MAX_GERAL], numero[MAX_GERAL], geral[MAX_GERAL];
int telefone, FP, SD, AM1, ALGA, CM;
}dados;

code to add info i need to sort "numero"

Code:

void adicionar(dados* contacto){
if (i<total) {
printf("
Introduza o Nome: ", i + 1);
scanf(" %[^

[code]....

View 7 Replies View Related

C++ :: String Array Sorting Into Alphabetical Order

Apr 14, 2014

I am trying to read information in from a file, each line of which contains a name in the form 'last, first middle'. I can successfully open the file and read it into an array that is roughly 2500 string in size. The problem comes when I try to sort the array into alphabetical order. I am using a sorting algorithm that we were instructed to use, found in our book. It is shown in the code. I would add the file that needs to be opened, but it is a few thousand lines long.

The error I am getting is:
Unhandled exception at 0x00A28628 in PeopleSearch.exe: 0xC0000005: Access violation reading location 0x00CC400C.

and I know it has to do with the sorting algorithm from using break points and running the program with that section commented out. I am stumped to why it is giving this error, as it seems that it is trying to access the array outside of the bounds of the array, but it shouldn't be

Here is my code:

#include<iostream>
#include<string>
#include<fstream>

using namespace std;
int main() {
string NameArray[2500], filename; //declare array and file to open

[Code] ....

View 2 Replies View Related







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