C++ :: Using Vectors And Strings / How To Output Name With Lowest Age
Nov 5, 2013
I have to write a program in C++, without using a selection sort, that outputs the name you enter with the lowest age. You input 5 names with ages and at the end it outputs the youngest person. This is what I have so far:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
[code]......
I Know for the second for loop there has to be if statements in it but I am so stuck on what to write next.
View 3 Replies
ADVERTISEMENT
Apr 19, 2012
I have a vector I want to add book titles to, then i want to print my updated vector. This is best I have come up with but the program fails at the getline line. why?
string book;
cout << "Enter book to add: "<< endl;
getline(cin, book);
books.push_back(book);
for(int i = 0; i < books.size(); ++i) {
cout << i+1 << ". " << books[i] << endl;
}
View 1 Replies
View Related
Apr 19, 2012
I was given a project to program a library catalog. One of the aspects is that we have to allow an administrator to add, modify, and delete books from the catalog. It was recommended to me to use vectors. So I initialized by hand a default book list, and now I want to be able to have an adminisistrator add books and then print the modified book list. Here is what I have got:
main () {
char yesorno;
string bookname;
vector<string> books;
[Code].....
View 7 Replies
View Related
Apr 17, 2014
I'm working on a project, and I'm trying to fill in various vectors from a given input file. The input file looks like:
<catalog>
<book id ="bk101">
<author>O'Brien, Tim</author> ....etc
My load vectors function looks like this: void load_vectors(vector<string>&id, vector<string>& author...etc)
I can't assume a limit on the number of books etc listed in this catalog, so I'm using the eof() function. However, I don't know how to write the loop to gather the correct strings and place them in the vectors.
Code: while(in.eof())
{ string text;
int index, index2;
getline(in, text);
int index = text.find("<author>");
int index2 = text.find("</author>");
a = index.lenght();
author.pushback[i] = text.substr(index + a, index2);
}
View 3 Replies
View Related
Dec 6, 2012
I thought that C++0x made it possible for vectors to be initialized with an initializer list, such as:
Code: vector<vector<string> > vv {{"hello", "goodbye", ""}};
I tried this syntax in both VS 2010 & VS 2012 Express For Desktop, and I get the same error in both compilers:
compiler error: non-aggregates cannot be initialized with initializer list
To put the code above in context, I'm going to have a .txt file with hundreds of thousands of string arrays, in initializer list format, such as:
{"string","string","string","","",""},{"string","string","string","","",""},{"string","string","string","","",""}...and so on
The first 3 strings in each array will be non-zero in length, and the last 3 strings in each array will be empty, as shown above.
I want to be able to cut and paste the arrays right into the declaration, either with:
string arrayOfArrays[0][6] = {{"string","string","string","","",""},{"string","string","string","","",""},{"string","string","string","","",""}...and so on };
or
vector<vector<string> > vecOfVectors = {{"string","string","string","","",""},{"string","string","string","","",""},{"string","string","string","","",""}...and so on };
I know I can do the first, but apparently the second declaration method with vectors won't work. I would like to work with vectors, but I'm not sure about the initialization. The .txt file will be what it is, so the initialization will have to be able to work with its 'array-like initializer' format.
View 10 Replies
View Related
Apr 16, 2013
I am currently confused on how to get the highest and lowest number from a list of 7 numbers for a File Output. Lets say i have 165 19 654 816 654 987 324. How would i get the 987 for the highest and the 19 as the lowest? Those numbers are not fixed numbers, i need to be able to input any combination of numbers and still be able to get the highest and lowest numbers from the list of 7 numbers.
View 1 Replies
View Related
Feb 18, 2014
Basically I need to make a program which asks for a business name and then keeps asking for more until user doesn't want to. Once more than 1 business is enter it should display the business and sort it alphabetically and keep displaying them each time another is added. I am lost on how to store the added business, sorting it and displaying the list.
Here is what I have so far.
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main () {
string business_name;
char selection;
[Code] .....
View 5 Replies
View Related
Jan 20, 2014
This code works very oddly.
Code:
#include <algorithm>
#include <cstdlib>
#include <iostream>
[Code].....
View 14 Replies
View Related
Feb 5, 2013
How do you use a for loop to iterate through strings to display them in a console?
View 3 Replies
View Related
Feb 8, 2014
I have an array of strings and a two dimensional array made up of floats. In the output for the strings (this array stores 10 divers numbers) I am getting only 8 of the numbers, then a core dump. What could cause this?
View 17 Replies
View Related
Feb 24, 2015
The requirement was to set the txt files information equal to a variable before and not to put it directly into the array.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX = 24;
struct applicant_info {
[Code] .....
the txt doc looks something like this: file name: jobs4.txt
View 2 Replies
View Related
Nov 25, 2014
The program is supposed to read in a string from the user and then output the number of each vowel that the string has. My first function is initializing the vectors, and the one that I'm having trouble with is the function used to read the string from the user and save it.
Here's my code:
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
// FUNCTION PROTOTYPES GO HERE:
void init_vectors(vector<char> & vowels, vector<int> & frequencies);
string read_text(const string & prompt);
[Code] ....
And I'm getting the error:
freq.cpp: In function ‘std::string read_text(const std::string&)’:
freq.cpp:74: error: no matching function for call to ‘getline(std::istream&, const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)’
I'm not too sure if I can't use the function getline here or if there is something wrong with the function prototype itself but I'm pretty sure there isn't an error there as it was given to me.
View 4 Replies
View Related
Mar 19, 2014
I create a list of vectors (a vector of n vectors of m elements).
std::vector <std::vector <int> > vsFA (n, std::vector<int>(n));
How I assign values? I try below, but not worked
void armazenaFA( std::vector <int> &vFA) // this function only knows about vFA
{ vsFA[n] [m]= simTime().dbl();
OR
vsFA[n].push_back(simTime().dbl());
}
View 1 Replies
View Related
Sep 19, 2014
This is probably a very basic question, but I need to create two vectors and then loop through the vectors and output each pair that is found.
The user will input min1 and max1 with step1 for the first vector and min2 and max2 and step2 for the second vector. Then the loops will go through and return the combinations will return each pair of the two vectors.
So if I input min1=1 and max1=10 and step1=1 and same for vector two the return would be:
[1,1]
[1,2]
.
.
.
[10,10]
This is for part of a homework assignment, but I can't continue on the assignment without first getting this simple part to work.
View 1 Replies
View Related
Feb 27, 2013
IM SO CLOSE to finishing this program, how to sort out and drop the lowest int, between 8 ints. Is there any way I can do this? I have these ints:
grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8
My program already assigns them values. How can I find the lowest value and drop it?I literally do not know where to start, and this is the last thing I need *.*
View 3 Replies
View Related
Oct 31, 2013
My problem is :
Code: numbers[10]={25,27,17,19,47,3,98,5,124,10};
You write a program at do below processes for above array.
You want a number 1 between 10 at user.
if user enter N value,program write to screen lowest N. number at array. For example user enter 2,program write to screen lowest secondary number of 5 value at array or user enter 10 value,program write to screen maximum number of 124 value at array.
But write the program with don't use sorting algorithm.
View 6 Replies
View Related
Jul 15, 2014
I am trying to encrypt a plaintext using DES in C. I read about the algorithm and how it works, but when i came to write the code i struggled. :
How to locate the lowest 8-bits in a 64-bit key ?
How to shuffle the plaintext according to the algorithm description ? (I read about bitwise operations, but i still cannot understand how i can use them to transfer for example the 5th bit to the location of the 30th bit)
Left shifting the key would not wrap the bits, so i just bitwise or with a mask that will add the bits that did not wrap around?
View 1 Replies
View Related
Aug 3, 2014
How to find a lowest grade in programing using the c++.
example: {65,89,100,76,80}.
#include<iostream>
using std::cout;
using std::endl;
int main() {
float grade=0;
[Code] .....
View 1 Replies
View Related
Nov 11, 2014
I dont know why I cannot get the lowest leftmost node in BST: segment fault
goToLeaf=root;
//now traversing right subtree from root node
else if(strcmp(curr->barcode, traverse->barcode)>0){
path='R';
traverse=traverse->right;
save=traverse;
cout<<"Right subtree exists. Value in right subtree"<<endl;
[Code] .....
Need this to delete node in two subtreed right subtree
View 2 Replies
View Related
Sep 29, 2013
How can I properly find the lowest and the highest temperatures?
#include <iostream>
#include <string>
using namespace std;
[Code]....
View 1 Replies
View Related
Feb 26, 2013
I'm having trouble, I want the inner loop to display the lowest and highest score. If I assign initial values for the high and low score, it won't always work (because if no/ all scores are above/ below my initial values...)
But without assigning initial values for highscore and lowscore, One of them will always be undefined during the first runthrough.
#include <iostream>
using namespace std;
const int AGRADE = 90;
const int BGRADE = 80;
const int CGRADE = 70;
const int DGRADE = 60;
int main() {
[code]....
how do i set this up so it stores a low and high score, and then compares those to each next number in the series?
View 6 Replies
View Related
Mar 12, 2014
I am trying to calculate the largest and smallest values using functions. I keep getting this (pointer-to) error
#include <iostream>
#include <conio.h>
using namespace std;
void getValues(int [], int);
void displayValues(const int[], int);
int largest(const int[],int);
int smallest(const int[],int);
void displayLargestSmallest(int,int);
[code]....
View 3 Replies
View Related
Jul 2, 2014
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
// Function prototype
void getScore(int& score, ifstream& inFile);
void calcAverage(int s1, int s2, int s3, int s4, int s5, int lowest);
[Code] ....
The program is suppose to report back the lowest number of 5 grades in a file..then it is suppose to report the average of remaining 4 higher scores..It appears to be reporting the correct average which tells me that it is reading the file and dropping the lowest score but it does not report back the lowest score first.
View 12 Replies
View Related
Apr 7, 2013
I cannot get this program from having a continuous loop. I need to have a user-defined loop.
Here is what I have so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int a,b,c,high,med,low;
[Code] ....
View 7 Replies
View Related
Sep 28, 2014
How do i sort numbers from highest to lowest using qsort? I dont have a code. I dont know how to use this one.
View 1 Replies
View Related
Oct 1, 2013
I have everything down except for the highest # and lowest number being displayed.
The arrays are 23, 4, 76, 89, 12, 43, 37, 67, 21, 14.
I have the average which is 38.6 but i stuck getting highest number and lowest.
View 7 Replies
View Related