C++ :: How To Store Names And Numbers In Array
Jul 25, 2014Can names and numbers be stored in one array ? Like a telephone directory?
View 1 RepliesCan names and numbers be stored in one array ? Like a telephone directory?
View 1 Repliesi 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() );
}
}
}
Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.
I'm stuck on how to put the prime numbers into an array.
The input file has the numbers 1 & 100.
Here's what I have so far.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");
[Code] .....
i cannot print the values stored in the array ?
Code:
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
double randf();
[Code] ....
This is in c. Write a program which asks for X numbers, and stores them in an array.
The program then asks the user to enter a number to look for, and tells the user how many times that number appears in the array of numbers (if any), and the array index which contain the number
Make an array of the indexes where the number was found, and then format your output to match my output.
Sample Run:
How many numbers would you like to enter: 5
Please enter a number:1
Please enter a number:2
Please enter a number:3
Please enter a number:4
Please enter a number:2
The numbers you enter were: 1, 2, 3, 4, 2
Please enter a number to find: 2
The number appears 2 times, at array ellements with indexes 1, 4
Press any key to continue . . .
So we're having an assignment for school where you code a Roulette game which simulates you playing and you can choose how many times you "play" to check how many times you'd win (if that makes any sense, im german :P)
Anyways, the problem is how do i store all the random generated numbers in an array while NOT doing this (it's just a snip):
Code:
void randomzahl(void){
int i;
int zahl5[5];
int zahl10[10];
int zahl100[100];
int zahl1000[1000];
int zahl10000[10000];
if(runden == 5)
[Code]...
Write a program which stores 10 decimal numbers in an array. For these numbers accept input from the users. Once the array is populated do the following:
Display each elements of the array
Display the sum of all the elements of array
I have to complete a project that i want to read float numbers from keyboard and store them into an array of 10 elements.! Every time that a number stored into array i want to compare with previous one if they have +-10 difference .. I want to keep only 10 elements into my array so every time that i give value a[0] replace a[1], a[1] replace a[2],a[2] replace a[3]. . . .and a[10] deleted.. So when all elements of the array are similar with +-10 values print out the array.!
View 1 Replies View Relatedive done a code for taxi's that arrive and depart, but i was wondering how i can use names of taxis as registration instead of numbers?
View 1 Replies View RelatedFor 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?
I have a dataset which is a coauthorship network (a .txt file).I want to replace all the names of the authors with a unique number(no matter what the number is but it's important these numbers should be unique).
I've opened the dataset in excel then copy the author's names to another excel file,then I want to replace the authors names with their row numbers. what should i do?
I am trying to write a program that would convert numbers of base 10, decimal numbers, to binary or hexidecimal numbers, base 2 and base 16. I want the program to run a loop through the various numbers input and store each number converted to the new type in a separate variable with the same basic name but different last letters/digits to differentiate between them and add them to the total.
Basically, I'm saying that i have the user input a number and letters. Let's say 15, d, b. So they want to convert 15 of decimal type to binary.
The program would then take the variable used to hold that number, and the other to variables to decide what function to perform on the number.
Then I will already have a variable initialized for the 3 possible conversions (binaryKey[], decimalKey[], hexideciKey[])
Then I want it to convert it and store the number at different places in the array to form the final number. Although, there is no way to predict what number the user will input, so there is no way of knowing initially where the converted place-value will need to be placed in the array.
I was wondering if there was a way to have the program run a loop where as the progression continues, it appends a number to the end of a universal name for the variables and then adds them together in the correct order creating the sequence that means that number.
In simpler terms:
Input a number: 15
Input type of base: d
Input converted type: b
Program then continually divides the number by 2, storing the remainder in a new variable
Such as: for(int i=1, i < (str(number).len), i++){
when i = 1, you would get
int number1;
[Code] ....
and so on. Is there a way to do this???
I am currently trying to write a code that will store PID numbers of a child after a fork, I have to be able to enter an amount that will be created, so far I have managed to be able to get them to print (which puts me on the right path as far as I am concerned) but I am having issues. Using the following code:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
[Code].....
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <algorithm>
using namespace std;
const int s = 12, p = 6;
int x[s][p];
[Code] ....
Names: P1 P2 P3 P4 P5 P6 AVER.
EVIKE 41 85 72 38 80 69 64.17
KKASV 65 68 96 22 49 67 71.86
YCXFX 51 61 63 87 66 24 70.64
FADPO 80 83 71 60 64 52 80.11
OEJUV 90 60 49 31 23 99 72.02
POEYL 94 11 25 24 51 15 48.67
VRVIP 13 39 67 97 19 76 59.94
QNQRQ 12 33 99 18 92 35 58.16
OOVAO 74 0 95 71 39 33 61.69
NCBXC 39 32 37 45 57 71 57.12
ATXDK 95 5 71 24 86 8 57.69
IXJSW 51 54 74 24 75 70 67.61
AVER. 58.75 49.15 72.35 51.11 62.68 56.81
1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice: 2
Names: P1 P2 P3 P4 P5 P6 AVER.
XXZRZ 41 72 38 80 69 65 60.83
OKETL 68 85 22 49 67 51 67.14
GZQRC 61 63 87 66 24 80 74.69
OJWAY 83 71 60 64 52 90 82.45
PSAJL 60 49 31 23 96 94 72.57
AOVLZ 11 25 24 51 15 13 35.26
CPWSR 39 67 97 19 76 12 57.54
IZCOB 33 99 18 92 35 74 68.09
IJTVD 0 95 71 39 33 39 57.52
LDVGY 32 37 45 57 71 95 65.75
MBORX 5 71 24 86 8 51 51.79
XOHGM 54 74 24 75 70 0 58.13
AVER. 40.58 70.72 50.98 62.66 56.56 60.05
1: Sort Alphabetically
2: Sort Grades Increasing Order (Student)
3: Sort Grades Increasing Order (Project)
4: End Program Enter choice:
Why my sort is not working. Also, I want to keep the same random numbers for the continuation of the program, I don't want new randomized values when I display the table.
I have a program that stores current a low numbers. The Object is to Store the low number every time time one is presented. so say I start the function the first number is the low number. but the trouble im having it once the function is called again it starts over(low number). Is there a way I can keep the function value once the function is called again? Any better way of doing this while keeping function in a class?
double a;
class rff{
public:
void FGH() {
doubleb=0;
cout<< "pick a number"<<endl;
[Code] ....
Rewriting a program to convert an array based list to a linked list. The program has a user guess a number [1-100] until the correct answer is guessed. I only want to give hints if a duplicate isn't guessed.
while (aGuess-> != p->guess) doesn't work and I haven't been able to troubleshoot myself.
while (aGuess->guess != p->guess) {
if ( aGuess->guess > a ) {
cout << "That's too high -- try again: ";
} // if guess > a
[Code] ....
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?
I want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.
View 7 Replies View RelatedI was working on float and double data types and to see the results i wrote this program:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main() {
ofstream outputF("output.txt");
double a = 1;
double outcome;
[Code] ....
Well I understand the part it cannot store infinite numbers. but if you take a look at the output for example (since it is too long i just added some of the outputs)
//---------------------
for the value of : 001
1
//---------------------
for the value of : 002
0.5
//---------------------
for the value of : 003
0.3333333333333333148
[Code] ....
if you look carefully at the value "5" and "10" results. it is awkwardly abnormal. which is something i couldnt understand. also it is the same with value "20", "25", "40", "50" and so on.
I'm trying to read names separated by a comma using array.
For example, the expected input would look like the following:
Juila,Francisco
Adams,Wong
I know you can use getline function and set the delimiter to comma. So like ....
getline(cin, lastName, ','); getline(cin, firstName);
But the program only read the last name and ignore the firstname.
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
I am trying to make a for loop that will print out chars in an array while using a #define before main. My problem is that each name has a different amount of chars in it. How do you account for that when you are trying to define a size? For example, I am playing around with the numbers and I just put 7 in for size:
Code:
#include <stdio.h>
#define sizeOf 7
//char personName( char * name[] );
char printName ( char * name[]);
[Code] .....
I am having problem with comparing first letter of every wordso that i can arrange them in array.
Code:
/*22/10/13 15:30
Arrange set of names in an array in alphabetical order
*/
#include<stdio.h>
main( ) {
int x,a,i=0,j;
char *temp, *str[]={
[Code] ....
I am getting unexpected output here :
Code:
himanshu
amit
nitin
saurabh
/* Implementation of a circular queue of Array containg names.. */
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# include <string.h>
# define QSIZE 5
typedef struct{
[Code] ....
I changed my code. but whenever i typed in the ILoveBacolod it takes it as a whole, and if i deleted it deletes the string not the letter. for example:
Enter String: ILoveBacolod
Enter a command: Delete (D)
Output: LoveBacolod
Enter a command: Delete (D)
Output: oveBacolod
Enter a command: Add (A)
Enter a character: z
Output: oveBacolodz
//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] .....
The program should store a character array in reverse order then display the reversed array. I have also included in the code that will display the actual characters into the array as it loops through. So I know the characters are being stored, but why doesn't it display the entire string when I call it?
Code:
#include<stdio.h>
int main(){
char str[50];
char rev[50];
printf("Enter Desired Text: ");
scanf ("%[^
[Code] ....
Is it just my compiler?