Go Back   Flash Flash Revolution > General Discussion > Chit Chat
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 10-15-2013, 03:48 PM   #21
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default 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.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник.
Kibblre is offline   Reply With Quote
Old 10-15-2013, 03:50 PM   #22
Superfreak04
FFR Veteran
FFR Veteran
 
Superfreak04's Avatar
 
Join Date: Jan 2007
Age: 33
Posts: 2,407
Default Re: Requesting help for programming/ CS majors?

We have to use arrays.
__________________
Superfreak04 is offline   Reply With Quote
Old 10-15-2013, 03:56 PM   #23
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default 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.
__________________


rushyrulz is offline   Reply With Quote
Old 10-15-2013, 03:57 PM   #24
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default 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:
Originally Posted by rushyrulz View Post
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.
Finding the size of a char array in C++ is sizeof(name).

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..
Kibblre is offline   Reply With Quote
Old 10-15-2013, 03:59 PM   #25
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default 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?
__________________


rushyrulz is offline   Reply With Quote
Old 10-15-2013, 03:59 PM   #26
shenjoku
Wubalubadubdub
FFR Veteran
 
shenjoku's Avatar
 
Join Date: May 2005
Age: 36
Posts: 1,697
Default 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);
The sizeof name part only works if you're using an array like you currently are. If you ever want to change to dynamically allocate the array so you aren't limited to some hard-coded number of characters then you would replace that part with whatever the calculated size of the array is (which I guess you'd do based on the user input). Or you could just replace it with 12 or whatever other hard-coded size you change to. Up to you

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;
to get the entire name. Oh well. Gotta learn how to use arrays at some point I suppose
__________________
boop

Last edited by shenjoku; 10-15-2013 at 04:18 PM..
shenjoku is offline   Reply With Quote
Old 10-15-2013, 04:03 PM   #27
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default Re: Requesting help for programming/ CS majors?

would you prefer a merge sort instead? it's nlog(n) instead of nē
__________________


rushyrulz is offline   Reply With Quote
Old 10-15-2013, 04:04 PM   #28
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by rushyrulz View Post
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?
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.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник.
Kibblre is offline   Reply With Quote
Old 10-15-2013, 04:07 PM   #29
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default 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
__________________


rushyrulz is offline   Reply With Quote
Old 10-15-2013, 04:07 PM   #30
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default 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..
Kibblre is offline   Reply With Quote
Old 10-15-2013, 04:12 PM   #31
Superfreak04
FFR Veteran
FFR Veteran
 
Superfreak04's Avatar
 
Join Date: Jan 2007
Age: 33
Posts: 2,407
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by Kibblre View Post
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;
}


Finding the size of a char array in C++ is sizeof(name).

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.
Hmm, I used this code and what happens is that I can type and hit as many letters as I want. Then once I type in, then it will end. Makes sense, although I'm supposed to make it ask me to enter a character each time I want to enter a new one.

"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.
__________________
Superfreak04 is offline   Reply With Quote
Old 10-15-2013, 04:12 PM   #32
shenjoku
Wubalubadubdub
FFR Veteran
 
shenjoku's Avatar
 
Join Date: May 2005
Age: 36
Posts: 1,697
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by rushyrulz View Post
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?
You can. You call std::cin() with std::setw(), passing it the number of characters you're expecting like this:

Code:
#include <iomanip> // Need this for std::setw()

char c;
std::cin >> std::setw(1) >> c;
This will only read in the first character input by the user. This will not limit them on what they can input though.
__________________
boop
shenjoku is offline   Reply With Quote
Old 10-15-2013, 04:14 PM   #33
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by Superfreak04 View Post
Hmm, I used this code and what happens is that I can type and hit as many letters as I want. Then once I type in, then it will end. Makes sense, although I'm supposed to make it ask me to enter a character each time I want to enter a new one.

"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.
Then you'd just have to move the cout statement from where it is to directly above the cin statement. That way it'll print out every time the loop restarts. So the while loop would look like:

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:
Originally Posted by shenjoku View Post
You can. You call std::cin() with std::setw(), passing it the number of characters you're expecting like this:

Code:
#include <iomanip> // Need this for std::setw()

char c;
std::cin >> std::setw(1) >> c;
This will only read in the first character input by the user. This will not limit them on what they can input though.
Yup, now I remember. I haven't used setw since last year and I totally forgot about it.
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник.
Kibblre is offline   Reply With Quote
Old 10-15-2013, 04:16 PM   #34
dAnceguy117
new hand moves = dab
FFR Simfile AuthorFFR Veteran
 
dAnceguy117's Avatar
 
Join Date: Dec 2002
Location: he/they
Age: 33
Posts: 10,094
Default 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]++;
}
and then uhhh you're gonna want to print it.
dAnceguy117 is offline   Reply With Quote
Old 10-15-2013, 04:20 PM   #35
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by Superfreak04 View Post
I have to use dummy's because the PC won't display anything without it.
Not sure if you caught this yet looking at my code, but that's what system("pause") will do for you.

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..
Kibblre is offline   Reply With Quote
Old 10-15-2013, 04:25 PM   #36
Superfreak04
FFR Veteran
FFR Veteran
 
Superfreak04's Avatar
 
Join Date: Jan 2007
Age: 33
Posts: 2,407
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by Kibblre View Post
Not sure if you caught this yet looking at my code, but that's what system("pause") will do for you.

Also, what level course is this? If this is an introductory course then he's making you do some tricky stuff for that level.
Yeah I noticed that right away lol. And yes this is intro. ;_;
__________________
Superfreak04 is offline   Reply With Quote
Old 10-15-2013, 04:29 PM   #37
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default 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
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник.
Kibblre is offline   Reply With Quote
Old 10-15-2013, 04:33 PM   #38
Superfreak04
FFR Veteran
FFR Veteran
 
Superfreak04's Avatar
 
Join Date: Jan 2007
Age: 33
Posts: 2,407
Default 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.
__________________
Superfreak04 is offline   Reply With Quote
Old 10-15-2013, 04:34 PM   #39
Kibblre
Caelondia Represent
FFR Veteran
 
Kibblre's Avatar
 
Join Date: Jul 2004
Location: A place of hearts and ghosts
Age: 31
Posts: 1,984
Default Re: Requesting help for programming/ CS majors?

Quote:
Originally Posted by Superfreak04 View Post
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.
So then you'd want the output like I described? It'll be tough to make it aAbBcCdD
__________________
Какой идиот придумал Бутерброд с дикобраза? Он хулиган и бездельник.
Kibblre is offline   Reply With Quote
Old 10-15-2013, 04:36 PM   #40
Air En Trance
FFR Player
 
Air En Trance's Avatar
 
Join Date: Oct 2013
Posts: 17
Default Re: Requesting help for programming/ CS majors?

this assignment is a horrible way to learn arrays and input
Air En Trance is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:37 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution