10-15-2013, 03:48 PM | #21 |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
By the way, do you HAVE to use arrays or can you use vectors? I personally prefer vectors.
EDIT: I totally missed this part: Ask the user to entire his/her name one letter at a time.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. |
10-15-2013, 03:50 PM | #22 |
FFR Veteran
Join Date: Jan 2007
Age: 33
Posts: 2,407
|
Re: Requesting help for programming/ CS majors?
We have to use arrays.
__________________
|
10-15-2013, 03:56 PM | #23 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
Re: Requesting help for programming/ CS majors?
you might need to use another include statement to make the .length operator (or C++ equivalent) work, I know C style languages are kinda bitches when it comes to that. Just google syntactical crap that is confusing you.
__________________
|
10-15-2013, 03:57 PM | #24 | |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
In case you hadn't been able to translate rushy's code, here's what part one could look like:
Code:
#include <iostream> using namespace std; int main() { char name[50]; int count = 0; bool valid = true; char inputChar; cout << "Enter a name one letter at a time and denote the end of the name with *: "; while(valid) { cin >> inputChar; if(inputChar != '*') { name[count] = inputChar; count++; } else valid = false; } system("pause"); return 0; } Quote:
Also, you might want to look into including the * as well for your later parts so you know to stop sorting there. Or make a new array using the count variable, but you'd have to make the new char array a pointer since you can't declare variable size char arrays unless you do.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. Last edited by Kibblre; 10-15-2013 at 04:00 PM.. |
|
10-15-2013, 03:59 PM | #25 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
Re: Requesting help for programming/ CS majors?
damn, C++ is so much nicer at handling IO than other languages I've programmed in..
Do you know if there's any way to restrict input to just one character, Kibblre?
__________________
|
10-15-2013, 03:59 PM | #26 |
Wubalubadubdub
Join Date: May 2005
Age: 36
Posts: 1,697
|
Re: Requesting help for programming/ CS majors?
lol bubble sort.
*ahem* If you want to let STL do the sorting for you it's very simple. Just call std::sort() like this: Code:
std::sort(name, name + sizeof name); You might want to consider looking up how std::sort() works and try to implement it yourself. It's always good to know how the internal stuff works. It's a shame you're limited to using an array. If you could use std::string you could just do a single Code:
std::string name; std::cin >> name;
__________________
boop Last edited by shenjoku; 10-15-2013 at 04:18 PM.. |
10-15-2013, 04:03 PM | #27 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
Re: Requesting help for programming/ CS majors?
would you prefer a merge sort instead? it's nlog(n) instead of nē
__________________
|
10-15-2013, 04:04 PM | #28 |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
I used Java more than C++, so I don't know if there's a direct IO function to handle it. You could use getline() to take in the whole line and then use substr() to cut it down to the first character only and finally cast it as a char.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. |
10-15-2013, 04:07 PM | #29 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
Re: Requesting help for programming/ CS majors?
yikes. I'd hate to have the program explode because someone was typing too fast and accidentally entered a two character input.
t h i s i s s o s t u p i d w h y a m i d o i n g t hi *EXPLOSION* s
__________________
|
10-15-2013, 04:07 PM | #30 |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
It wouldn't explode. It would actually read it/print it later as hi.
Enter a name one letter at a time and denote the end of the name with *: he l l o * (print loop went here, printing 1 char at a time) he l l o Press any key to continue . . . EDIT: Actually, it indexes it correctly. h is index 0 and e is index 1. Really odd why it prints like that then.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. Last edited by Kibblre; 10-15-2013 at 04:10 PM.. |
10-15-2013, 04:12 PM | #31 | |
FFR Veteran
Join Date: Jan 2007
Age: 33
Posts: 2,407
|
Re: Requesting help for programming/ CS majors?
Quote:
"Enter a name one letter at a time and denote the end of the name with *: E "Enter a name one letter at a time and denote the end of the name with *: R "Enter a name one letter at a time and denote the end of the name with *: I "Enter a name one letter at a time and denote the end of the name with *: C etc. At least, that's how we've been taught. It's so that we can make sure it's working properly I guess.
__________________
|
|
10-15-2013, 04:12 PM | #32 | |
Wubalubadubdub
Join Date: May 2005
Age: 36
Posts: 1,697
|
Re: Requesting help for programming/ CS majors?
Quote:
Code:
#include <iomanip> // Need this for std::setw() char c; std::cin >> std::setw(1) >> c;
__________________
boop |
|
10-15-2013, 04:14 PM | #33 | ||
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
Quote:
Code:
while(valid) { cout << "Enter a name one letter at a time and denote the end of the name with *: "; cin.get(inputChar); if(inputChar != '*') { name[count] = inputChar; count++; } else valid = false; cout << endl; //put and end line here for better readability } Quote:
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. |
||
10-15-2013, 04:16 PM | #34 |
new hand moves = dab
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
|
Re: Requesting help for programming/ CS majors?
here's a sketchy solution for step 3 using C-style everything (which seems to work? based on the sample code?) and keeping rushy's variable names.
no guarantees about just plugging this in, but you should be able to see what your objective is here. Code:
char letter_a = 'a'; int value_a = (int)letter_a; int distribution[26]; for (int i=0; i<26; i++) { distribution[i] = 0; } for (int i=0; i<name.size(); i++) { int value_myLetter = (int)name[i]; int elemNumber = value_myLetter - value_a; distribution[elemNumber]++; } |
10-15-2013, 04:20 PM | #35 | |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
Quote:
Also, what level course is this? If this is an introductory course then he's making you do some tricky stuff for that level.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. Last edited by Kibblre; 10-15-2013 at 04:23 PM.. |
|
10-15-2013, 04:25 PM | #36 |
FFR Veteran
Join Date: Jan 2007
Age: 33
Posts: 2,407
|
Re: Requesting help for programming/ CS majors?
Yeah I noticed that right away lol. And yes this is intro. ;_;
__________________
|
10-15-2013, 04:29 PM | #37 |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
Question about part 2: does he want capitals included too? It'll make it even harder if you have to sort lower case letters combined with capital letters instead of making them all lowercase. If you were to use standard sorting methods, the capitals would sort themselves to the beginning in order then the lower case letters would be in order, like ABCDabcd
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. |
10-15-2013, 04:33 PM | #38 |
FFR Veteran
Join Date: Jan 2007
Age: 33
Posts: 2,407
|
Re: Requesting help for programming/ CS majors?
I believe she wants us to include capitals. Even though it's up to the user whether or not you wanna type in a capital.
__________________
|
10-15-2013, 04:34 PM | #39 |
Caelondia Represent
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
|
Re: Requesting help for programming/ CS majors?
So then you'd want the output like I described? It'll be tough to make it aAbBcCdD
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник. |
10-15-2013, 04:36 PM | #40 |
FFR Player
Join Date: Oct 2013
Posts: 17
|
Re: Requesting help for programming/ CS majors?
this assignment is a horrible way to learn arrays and input
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|