C++ :: Inserting File Of Names And Sorting Alphabetically?
Feb 25, 2013
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
and so on .....
View 1 Replies
ADVERTISEMENT
Apr 9, 2014
//Build a program that uses a single-dimension array to store 10 names input by a user.
//After inputting the names, the user should see a menu with two options to sort and print the 10 names in ascending or descending order.
insert
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char names[10];
char temp[10];
int count,i,j;
int sort;
[Code] .....
View 10 Replies
View Related
Feb 25, 2013
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++.
View 2 Replies
View Related
Dec 10, 2014
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.
View 9 Replies
View Related
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
Aug 30, 2014
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.
here's my code btw:
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <algorithm>
#include <iterator>
#include "Movie.h"
[Code]...
View 2 Replies
View Related
Aug 25, 2014
I am reading a file and storing the data (all strings) into a vector. How would I sort this alphabetically?
View 4 Replies
View Related
Feb 24, 2013
All I wanted to do is to sort the car names according to their mileage. And display the output with their car names. This is what I've made
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int j;
class car
[Code].....
I need to take 5 car details and sort them according to their Mileage..
View 4 Replies
View Related
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
Sep 26, 2012
I cannot manage to get the code for sorting the names in alphabetical order.
#include<stdio.h>
#include<string.h>
typedef struct{
char criminalName[10];
char criminalCase[20];
[code]....
View 3 Replies
View Related
May 7, 2013
For my project I have to sort 5 numbers and 5 names using a template bubble sort. I have one header for the numbers, and one for the names. This is what I have so far for my testing page:
#include "Floatheader.h"
#include "Nameheader.h"
#include <string>
int main ()
myFloat obj1;
myFloat obj2( 2.2, 5.1);
[Code] .....
I have to create a template to look like this: template<>....with a class inside the arrows. Then, I have to use bubble sort to sort the 5 names and number objects I have created. Sorting the names and numbers and also using templates?
View 1 Replies
View Related
Oct 29, 2014
I am at a lost of how to sort names in alphabetical order after having the user input them into a linked list. I manage to create a program that did have the person input names into the linked list and when it is printed it displays the names in the order of how the user inputted the names.
#include <cstdlib>
#include <iostream>
using namespace std;
#include <string>
class NodeType {
public:
string NodeValue;
[Code] .....
View 1 Replies
View Related
Oct 24, 2013
I am having problems sorting data... I don't know to to go about it here is my code:
<code>
#include <iostream>
#include <string>
using namespace std;
int main () {
int i;
struct person
[Code] ....
i want to sort it out so that it can output names and ages in ascending order.
View 2 Replies
View Related
Mar 28, 2014
I'm trying to insert a structure into a binary file, then read it back out into a "temporary" structure and output some values.
#include <iostream>
#include <fstream>
using namespace std;
struct b_tree_node {
int num_keys; // number of keys in this node
int key_val[3]; // key values (0 to num_keys - 1)
int child[4]; // child file addresses (0 to num_keys)
[Code] ....
View 12 Replies
View Related
Mar 13, 2015
I'm having a problem in my Library assignment, this section of my code is for reading in books saved in a 'book.dat' file on my desktop and inserting them into the linked list. It kind of works, but say if there is two books in the file, it only saves the second book twice.
eg in book.dat:
123 book1 Tolkien 2009 0
111 book2 Rowling 2009 0
So once these are read in, and I call my method displayAll(), it would display the second book twice..
void importFromFile(FILE *fp) {
struct book *aBook;
struct node *aNode;
aBook = (struct book *)malloc(sizeof(struct book));
[Code] .....
View 6 Replies
View Related
Jan 19, 2014
I have almost a hundred names in a text file that I want to convert to email addresses and save to another file. I seem to have it working, but it doesn't print the full names in the email prefix. The output I'm looking for is Doe_John@livebrandm, but I'm only getting D_J@livebrandm. I'm not sure what I should specifically be reading up on that applies to this directly.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fpin=fopen("namesIN.txt", "r");
FILE *fpout=fopen("emailOUT.txt", "a");
char first[20],last[20],inbuff[1500];
[Code]...
View 9 Replies
View Related
Feb 10, 2013
i have a vector of stores. i would like to delete the specified choice(store) from the list. Here is what i have but my erase statement is wrong and wont compile.
void Store::deleteSpecifiedStoreFromList(string choice) {
for (int i = 0; i < this->stores.size(); i++) {
if(this->stores[i].getStoreNames() == choice) {
this->stores.erase( std::remove_if( this->stores.begin(), this->stores.end(), choice ), this->stores.end() );
}
}
}
View 4 Replies
View Related
Feb 9, 2013
I am trying to create an array of file names such that when I want to open one of the files, who's name is given in the array, I can call that element of the array. My code for making the array is the following,
Code:
char file_name[40];
char *file_locations[N]; // array of N names (*)
for(ii=0; ii<=N-1; ii++){ // printing the names of all the files P1_8mag_1.txt - P1_8mag_N.txt
sprintf(file_name, "P1_8mag_%i.txt", ii+1);
[Code]....
The problem with this is that in the first step: all elements of the array "file_locations" are the name of the last file in the loop (in this case "P1_8mag_N.txt")What is wrong with this?
View 12 Replies
View Related
Oct 2, 2014
I have .db3 file, and he has 14 tables,and every table has certain number of columns. Example i have table called "BASIC_INFO" and that table has columns "First Name", "Last Name" and "Age".
How can i get name of table and name of every column,so if i some day add column "Male" i get name of this column too. I need first to calculate number of columns,put that in some integer, and then for example create string array which will contain : array[0] = "First Name" ,array[1] = "Last Name"...
SQLiteConnection myConn = new SQLiteConnection("Data Source=" + DB3Path + ";Version=3;New=False;Compress=True;");
//string query = "Select * From " + DB3Path + ".INFORMATION_SCHEMA.COLUMNS";
string query = "Select * From BASIC_INFO.INFORMATION_SCHEMA.COLUMNS;";
SQLiteCommand sqCommand = new SQLiteCommand(query);
[Code] ....
I tried this too:
string query = "select * from INFORMATION_SCHEMA.COLUMNS"
+ "where TABLE_Name='BASIC_INFO'"
+ "order by ORDINAL_POSITION;";
string query = "SELECT TOP 0 * FROM BASIC_INFO";
View 2 Replies
View Related
Jan 16, 2014
I need writing code for automated incremental file names. This is what I have right now.
FILE *output;
char output_file_name[ NAME ];
printf( "
Enter an output file name: " );
[Code] ....
View 3 Replies
View Related
Jun 19, 2014
I am having trouble reading in a file of 10 names into an array. Ive already allocated the memory, I just keep getting a seg fault when I try and read in the names.
Code:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_STRING_LEN 25
void insert_data(char **strings, const char *filename, int size);
void allocate(char ***strings, int size);
[Code] ....
And then the list that I have to read in is as follows:
matt
susan
mark
david
aden
phil
erik
john
caden
mycah
View 1 Replies
View Related
Feb 5, 2013
I am reading text from a file and trying to set names to structs. Here is the input file
Code:
2
3
Quincy Richard Steven
Donna Elizabeth Francine
5 2 9
4 5 7
5 9 6
4 6 5
7 8 9
6 9 1
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_CHARS 20
// Structure that has 2 properties: name and scores.
struct person
[Code] ....
In the nested for-loop it should read in the name of each men and print it out, like so:
Code: Quincy Richard Steven
However it is printing out:
Code: QuincyRichardStevenDonnaElizabethFrancine
View 9 Replies
View Related
Jul 22, 2014
How can I take in a path name like "C:myfolderfile.txt" where the user enters exactly that? I've tried putting the arg into a string, then looping through the string to find the '\', but by that time it is too late as c++ considers the '' as a escape character.
Is this even possible? I've googled it and everyone just says to make the user input the path with double \ or with a /.
View 1 Replies
View Related
May 26, 2013
Here is a working C++ program and its output that reads the names of a certain number of functions whose names are written in a disk file that provides the control parameters in a near-real time fashion. Based on this information, the program calls those functions whose names were given in this text file as parameters. The method I have used is to build a map of functions that connects the names of the functions to the actual functions. Once this map is created, then it is very easy to iterate in such a way that only those selected functions are called.
So far this is working well, and it makes the logic of the code easier because ultimately there will be a large inventory of functions (probably hundreds of functions), and this way of pre-building a map of functions avoids writing hundreds of if statements in the code. Of course, pre-building this reusable map in the background is still equivalent to writing that many if statements, but at least it makes the code very compact and much more automatic, since it is done only once.
But I now have a related question: In this case (when the selected subset of functions to call is given as incoming data as in this example), does C++ make it possible to avoid using maps of functions, by directly applying the string variable that holds the name of the function in order to call the original function immediately For instance, if a string variable s = "MyFunction", then is there a more direct way of using this string as if it were the actual function whose name is spelled exactly in that way? This would make the code even more compact.
Here is the sample test code for the map of functions, and its output:
First of all here is the text file "FileForNamesOfFunctions.TXT" that contains the part of the "data", which is the set of functions select from from the inventory and only call these:
Code:
function2
function3
function5 And here is the C++ code that uses this "data":
Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
[Code] ....
View 8 Replies
View Related
Oct 28, 2013
I just recently started looking into C++ programming so I don't know much.
I was wondering is it possible to write a program to pick a random name from a list of names, which are in a .txt file? or if I could ask the user to input the list of names and then let the program pick a random name?
View 6 Replies
View Related
Apr 24, 2014
I have a lab with the following instructions:
Manually create an input text file called Lab22BInput.txt with the following data:
Dove
Doe
Alston
Zebra
Egg
Write a program that will read the names from the input file. Print out each of the names read to the screen. The program should go through the list of names and determine which comes 1st in the alphabet. The program should determine how many letters are in this name. Print out the name that comes first in the alphabet and the length of the name.
I have created the input file, and the data correctly outputs to the screen when I run the program. However, I do not know what kind of logic to use to sort them alphabetically and determine the amounts of characters.
So far I have the following:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string str1, str2, str3, str4, str5;
[Code]...
View 2 Replies
View Related