I have a homework assignment in C++ where I have to: "Write a program which asks user to input 10 students names. Store them in an array. Convert all the names to UPPERCASE without using any built-in functions. You must write the function to do that yourself. Lastly, sort the name in alphabetic order."
Here is my code so far, but my program won't compile, and the message it gives me is gibberish.
#include <iostream> using namespace std; void sortNames(string name[], int cap); void toUpper(string name[]); int minIndex(string name[], int i); void sort(string name[]); void swap(string name[], int i, int j);
I'm using a database and im trying to sort a 2D array info[51][10] that contains 51 pieces of records and 10 different fields for each record. And, now I'm trying to sort a desired field in the 2D array alphabetically.
However, the other fields within the same record should be swapped together. (So that the information of the same records stays together).
Also, I am constantly experiencing a run-time error. Sometimes my program works sometimes the whole thing crashes... By opening the code in different folders sometimes works. But the problem is still here. Is there any way to fix this error?
bool swapped =true; int j=0; string tmp[10]; swapped =true; j=0;
is this correct? I used this sorting with numbers i don't know if it is the same with strings. When I run it, there are no errors detected, but when i try to view it, the inputs does not appear.
I am doing a homework assignment for my class were I have to ask the user for a name of student then use linear search and then display the students name and mark, afterwards I need to sort and then ask the user again for a name and this time use binary search.
The only problem is when I enter the same student in linear search and binary search I get different marks for the student. For example: If I enter Pore,Bob I get a class mark of 91, Then is sort the names and marks array and now when I enter Pore,Bob for the binary search I get a class mark of 77 instead of 91? I there way to make it so the marks array corresponds to the names array?
void selectionSort(string names[], int marks[],int numElts) { //Sort the names array int startScan, minIndex; string strName; for(startScan = 0; startScan < (numElts - 1); startScan++)
I can write code that can sort arrays with Bubble, Selection and Insertion algorithms but I'm not sure how to have them be called and return a value 3 different times with 3 different sizes. For example, I need it to return 10, 100 and 1000 but I'm stuck.
#include <stdio.h> void selectionSort (int list[], int last); int main()
Been working on this program for a while. It's currently broken in several parts but it at least reads and stores the data into the arrays correctly. The problem is writing the sort function and the swap function. The other problem is writing both of these to keep the correct ages with the correct names.
/* Write a program to allow the user to enter up to ten people with their age. The names will be a full name consisting of a last, possibly a middle initial, and a first name. The full name will be no longer than 40 characters in length. The full will be stored in an array of strings, a two dimensioned array of characters. The ages will be stored in an array of integers. Manage the arrays as parallel arrays. Data entry will be from the keyboard and will read the full name followed by the age. Data entry will terminate when the arrays are full or when nothing is entered for the full name. Use a subroutine to enter the data and pass the arrays to the subroutine, do not use global arrays. Once the data is completely entered, use another subroutine to print out the arrays to the screen. Then use a subroutine to sort the data on the full names, ascending order. Reuse the print subroutine and print the sorted data out to the screen. Write another subroutine which sorts the data on age as the primary sort and full name as the secondary sort. Finally reuse the print subroutine to print the data to the screen. The main program will call the data entry function, followed by the print function, the name sort function, the print function, the age sort function and finally the print function. All data will be passed to the functions, no global data. */
I'm trying to write a code that takes two arrays from the user (presumably in ascending order) and then passes the sizes of both arrays and a pointer to each to a separate "int* mergeArrays" function that will merge sort the two. I've written a lot of the code, but I can't get it to compile. I get errors: lab6.c: In function "main":
lab6.c:31:14: error: expected expression before "int" mergeArrays(int* firstArray, int size1, int* secondArray, int size2); ^ lab6.c:31:14: error: too few arguments to function "mergeArrays"
I'm still fairly new to c++ and am having trouble with dynamic arrays. My task is to create an array for test scores. The user needs to define the size of the array and then input data to later sort and calculate the average.
Below is what I have so far. I am struggling with the user input part. I receive the following errors for the data input of the individual scores:
"error C2108:subscript is not of integral type" "IntelliSense:expression must have integral or unscoped enum type"
Code :
#include<iostream> #include<iomanip> using namespace std; int main() { //user input total number of scores cout<<"Please enter the total number of test scores."<<endl<<endl;
I've tried searching for answers around the web but everyone is using syntax that We haven't been taught before in class yet. I understand that the string library is probably the most efficient way of doing this but is there a way without using that library? Like using if, for, while etc. instead?
I've been told that using anything else other than the string syntax is far to complex but I think the more complex it is the more I will understand it.
I understand multimaps are key ordered. I have no problems with ints but when I put my char arrays in they are not alphabetically ordered. I must use char array and not <string>. Is it possible to alphabetically order them with char*
39 int c; 40 User *user; 41 char nameH[200]; 42 char line[200]; 43 int ageH; 44 double wH;
I'm trying to write a program that reads in from a .txt file the movie title, rating, director, actors etc. All I want to do is to just sort movie titles alphabetically and print all its attributes(director, actors). I tried using sort( movies.begin(), movies.end()) method, but it doesn't work.
I'm trying to finish this project which is supposed to read two files, and merge them alphabetically. I've written this code, and it compiles. But it isn't actually doing anything??The console opens and closes immediately upon running.
Code: #include <iostream> #include <fstream> #include <cstdlib> #include <string> using namespace std; #define hisFamily "The Adopted.txt" //His family #define herFamily "The Originals.txt" //Her family #define ourFamily "The Big Picture.txt" //Our family
I'm trying to arrange names alphabetically from a text file. Inside my textfile, it's like : "John", "Edward", "Peaches", "Anna"... etc.(It has thousand more names, all with quotations, separated by comma and I think it's not typed line by line... but using only one line). How can I read each name separately?
this code, it works if the text file contains names separated by lines and without commas and quotations. I do not know with the case I've stated above.
string numbers[1000]; string line; string number; string y; string x; int z = 1; ifstream myfile; myfile.open("names.txt");
[Code]...
This only shows the data inside text file. I'm new in c++.
A teacher has asked all her students to line up single file according to their first name. For example, in one class Amy will be in front of the line and Yolanda will be at the end.
Write a program that will read in a file of names. Names should be read until there are no more names to be read. Use LineUp.txt as a test file for your program.
Once all the names have been read in display which student will be at the front of the line and which one would be at the end of the line. You may assume that no two students have the same name.
These are the name in the LineUp.txt file if needed: Cooper Gavin Joseph Sierra Kacie Dylan Kaylee Will
Example radix sort function to sort an array of 64 bit unsigned integers. To allow for variable bin sizes, the array is scanned one time to create a matrix of 8 histograms of 256 counts each, corresponding to the number of instances of each possible 8 bit value in the 8 bytes of each integer, and the histograms are then converted into indices by summing the histograms counts. Then a radix sort is performed using the matrix of indices, post incrementing each index as it is used.
Code: typedef unsigned long long UI64; typedef unsigned long long *PUI64; PUI64 RadixSort(PUI64 pData, PUI64 pTemp, size_t count) { size_t mIndex[8][256] = {0}; /* index matrix */ PUI64 pDst, pSrc, pTmp; size_t i,j,m,n; UI64 u;
It's compiling ok, and displays the first call to the printf function from main. However, after this I get the 'Segmentation fault (core dumped)' at the terminal, presumably from the call to the dictionarySort function.
I had a little look around and found it is something to do with non-existent or not available memory addressing, I think? Even so, I can't figure out what is causing the issue in my code.
You will write a program that uses a multidimensional array having 3 rows and 8 columns and sorts each of the rows using both a bubble sort and a selection sort.
You must declare the array inside of main. You will have a for loop containing the calls to bubbleSort and selectionSort. You need to pass into function bubbleSort and selectionSort the following: 1) each column of the multidimensional array, 2) the size of the column, and 3) a particular row number of the multidimensional array to be used for printing out the "pass" shown on the following pages.
I keep getting an error that the identifier for bubbleSort and selectionSort is not found. (Error C3861) Also, I feel like I'm missing something in int main() to get it to sort properly.
# include <iostream> using namespace std; int main() {
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) { int comm = 10; int targ = 5; int death; struct AI_WORDS
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {