C++ :: Program To Pick A Random Name From A File With List Of Names

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


ADVERTISEMENT

C# :: Pick Up Random Word From Text File And Use It As Nick

Apr 26, 2013

I got this code here id like for it to pick up a random word from a text file and use it as the nick in this line

Code:
SetNick(GetRandomString(10));

how could i do it heres the full code for the client

Code: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluorineFx;
using FluorineFx.Messaging.Adapter;

[Code] ....

View 8 Replies View Related

C++ :: Random Pick Without Repeats

May 9, 2014

What I'm trying to do is to have the program pick random people for different jobs. The user enters the number of people, then, enters both jobs and the people's names. I need the program to pick random people, but randomly pick again if the person has already been picked, so, no repeats. I have the program picking random people, but I can't get it to not pick the person again. I'll run it and there will be no errors, but it's almost like Xcode completely bi-passes the for/if to check if it's picked the person already.

Below is the code.

#include <iostream>
#include <math.h>
using namespace std;
int main() {
int runagain=0, correctnames=0, versiondesciosion=0, correctjobs=0;//vars that make descisions for running again
rerun:

[Code] ....

Dont look at the "fun" version for the switch statement. It's not ready yet, I'm just having trouble with the random thing.

View 3 Replies View Related

C++ :: How To Pick Random Number From Array

Oct 24, 2013

Basically we have this 7 bit binary code, and i would like to pick out 3 numbers randomly from it, how do we do that ?

for example 1011101

int Num[7];
for(int i=6; i>=0 ; i--)
{Num[i] = binary % 2;
binary = binary/10;}

View 3 Replies View Related

C :: Convert List Of Names From One Text File To Email Format In New File

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

C++ :: Delete Specified Names From A List Of Store Names?

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

C :: Creating Program That Can Pick Words In A String Or Array

Apr 24, 2013

Creating a C program that can pick words in a string or array and save it in different location, later combine everything in one string or array. It will be using simple programming C code. For example (arrays, pointer) but not interrupts or other string functions.

In a sentence like this:
Size= 70
$--GSV,x,x,x,x,x,x,x,...*hh $--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,b,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh $--GLC,xxxx,x.x,a,x.x,a,x.x,a.x,x,a,x.x,a,x.x,a*hh $--GSA,a,a,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x.x,x.x,x.x*hh

The program must capture the $--GGA string then extract from this string:

1) hhmmss.ss
2) IIII.II
3) a (if a = to N or S replace N or S with + or - respectively )
4) yyyyy.yy 5) b (if b = to E or W replace E or W with + or - respectively )

Save them in an array and display as well. After all the saving, the program should combine them to one string. That the final output.

View 7 Replies View Related

C++ :: Write A Program That Will Read Names From Input File

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

C :: How To Generate Random Color Names

Sep 7, 2013

I want to print different color names for "nb " times . I get the number " nb " from the user or from text file . if " nb = 3 " then I want to print any 3 different color names which means that I may print ( red , green , blue ) for example . and if " nb=5 " then I have to print any five different color names ( pink , blue , black , red ,white ) fore example .

Note : " nb " may be a large number ( 17 for example ). How can I do this ?

View 2 Replies View Related

Visual C++ :: Rename Files With Random Names In A Folder

May 30, 2014

I need a code for renaming multiple(bulk or all ) files in a folder.

I found one batch file script but it renaming with numbers only. But i want differntly.

[URL] .....

Example:

In a folder there are 100 images and all numbered with some digits or names.

assume that all images are belongs to "john" , so i want to rename all images with "john+ a random string".

here a random string means -> it has an array with 3000 english words, (you can predefine them by downloading from dictonary).

In the script the 3000 names are fixed, but the 1st name will be changed by my wish. that my be john, mary, sai, pavan etc...

Suggestion: you do not need to enter all 3000 words in array manually. some javscript codes are there to read input of each and evey line and them into an array.

View 2 Replies View Related

C++ :: Program To Read Middle Names Within Text File - Full String Not Appearing

Oct 24, 2014

I've a problem here...

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <iomanip>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])

[Code] ....

The program needs to be able to read the middle names within the text file named Info2.txt

Simply adding the Mname or any related value where the other to name values doesn't do anything and only the 1st line appears on the output.

Don Jon111012
Jack Bo Todd151015
Jill Jo Jane161011
Bob Jack Chuck 131513
Da Fu111012

That is the correct way it appears in the text file. Also I know it's commented out, but that just to keep the program from crashing.

current output

Survey Results:

Name Results
Don Jon 33.00

This is the Info1.txt file info by the way.

Ken A202017
Gus B151015
Bill C151512
Jara C151720
Lu E101510
Chow B171015

And the output

Survey Results:

Name Results
Ken A 57.00
Gus B40.00
Bill C42.00
Jara C52.00
Lu E35.00
Chow B 42.00

Which when ran with Info1 selected, it is the correct output I'm looking for. I've tried getline and other solutions and they didn't work.

View 1 Replies View Related

C++ :: Read List Of Random Numbers From Input File And Calculate Statistics?

Nov 11, 2013

I need my program to read a list of numbers from and input file, random.txt, and calculate the following statistics on those numbers:

A. The number of numbers in the file.
B. The sum of all the numbers in the file.
C. The average of all the numbers in the file.
D. The largest number in the file.
E. The smallest number in the file.

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

[Code]......

This is what I have so far but I'm not sure if it is right. I can't get the input file to open.

View 3 Replies View Related

C++ :: Sorting Names Within Linked List

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

C++ :: Use Functions In A Program To Show Names And Grades

May 19, 2013

how to use functions in a program to show the names and grades of students, their average, total, highest and lowest grades.

View 1 Replies View Related

C++ :: Program Crashes When Reading Linked List From File?

May 5, 2013

Why program crashes when reading linked List from file?

#include <iostream>
#include <fstream>
using namespace std;
struct link{
int data;
link* next;

[Code] .....

View 4 Replies View Related

C++ ::  program That Reads Into String Object A Name With Three Blanks Between First And Last Names

Oct 4, 2014

" Write a program that reads into a string object a name with three blanks between the first and last names. Then extract the first and last names and store them in separate string objects. Write a function subprogram that displays its string argument two times. Call this function display the first name for times and then to display the last name six times."

I completed coding the first part of this task with the strings and combining strings together. However, i have having trouble with the other half of this task. It begins from "Write a function subprogram to display the last name six times." This is where i have so far --

#include <iostream>
#include <string>
using namespace std;
int main()
{
// Defining the strings

string firstname, lastname;
string wholename;
string greet = " Hi ";

[code]....

View 2 Replies View Related

C++ :: Adding Employee Names In Function Arranged Program

May 13, 2014

The program that I have written below is working. It calculates a number of payroll type variables and most recently the net pay average (All this is working 100%).

My problem is that I need to add first and last employee names to the program but every time I do this I end up ruining the working program. I've successfully added first and last names to similar programs in the past(ones that make use of an array and while loop) but never to a program that uses functions (I always have problems doing this).

My question is what codes do I use to add a first and last name variable and where do I put those codes within my program so it runs/displays correctly.

I think the coding must be similar to what I've used in the past charr and of course firstname[i] and lastname[i] lines.

Current Input File:
16454025.00
89324020.00
71044012.50
28164026.00
53874021.00
67804013.50
56414011.25

90006025.00
90015020.00
90025523.00

Ideal input file (would include names) Example.
1645 Bob Smith 40 25.00

Syntax:

#include <iostream>
#include <iomanip>
#include<fstream>
using namespace std;
//function prototypes
int readalldata(long int[], int[], float[], const int);
void findovertimehours(int[], int[], int);

[Code] .....

View 8 Replies View Related

C/C++ :: Program To Emulate Shopping List - File Not Reading Correctly

Jan 28, 2015

I have written an program to emulate a shopping list. Everything works fine, until I try to read in from a file. Here is my read and write code (the write code looks like it is working ok, but I figured I would include it just in case), and an example of what happens to a list that has been written, then read back in.

I took this list, and wrote it to a file, then read that file back in. The .txt file looks like everything was written out properly, but when I try to read that exact same list back in, this is what I get:

View 10 Replies View Related

C++ :: Voter Program - Input Names And Votes / Output Who Won The Vote

Apr 27, 2013

In my class we were supposed to write a program from the book that inputted the names and votes and the program is supposed to spit out who won the vote. I did this then while i was reading the assignment from the instructor I noticed he wanted the information inputted from a TXT file instead of manually inputting it. I cannot seem to get it to work....

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define N 5
char names[N][20];
float votes[N];

[Code] ....

here is the txt file

Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Ashtony 1800

View 2 Replies View Related

C :: Array Of File Names

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

C# :: How To Get Column Names From Db3 File

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

C++ :: Automated Incremental File Names

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

C :: Seg Fault When Reading File Of Names Into Array

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

C :: Reading Text From A File And Trying To Set Names To Structs

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

C++ :: Arrange Names Alphabetically From A Text File

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

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 View Related







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