Requesting help for programming/ CS majors?
This is probably easy for most, but I can't seem to figure it out. This is in C++ btw.
#include <iostream> using namespace std; int main() { int name[12]; int i; for(int i=0; i<12; i++) name[i] = i; for(i=0; i<12; i++) cout << "This is letter ["<< i <<"]: " << name[i] << "\n"; } int dummy; cin >> dummy; return 0; } I have to use dummy's because the PC won't display anything without it. This is what I have so far, I'm not really sure about what to do from here. I'm not even sure if this is correct, lol. Help> :???: |
Re: Requesting help for programming/ CS majors?
I have nooo experience with C++ sorry, I'm sure someone else will come to the rescue soon. in the meantime
Quote:
for each element in the array, you're storing its number. is that intentional? sorting the array in alphabetical order manually would be the trickiest part of this assignment by far. do you know if you're allowed to use C++ library functions to do the work for you? for the frequency of letters, I would make another array with 26 elements. each element in the array should have an int initialized to 0. the 1st element represents 'a', the 2nd represents 'b', etc. as you read in each character from the input, you'll want to compute the 0-25 value based on the character's ASCII value, and then increment (+1) the int stored in that letter's element. ^ ew that's a yucky low-level way of doing it. again, you should find out if you're allowed to use all of the functions available to you. good luck! |
Re: Requesting help for programming/ CS majors?
you're using the same control variable for nested for loops. EDIT: nvm confusing without curly braces, loops aren't nested.
Will edit with other thoughts gimme a min Code:
#include <iostream> to read in the inputs, you should use a scanf and assign those to name[i] instead of just assigning i to name[i]. Then you can loop through the array and perform the sorting algorithm. let me code up an example real quick.. |
Re: Requesting help for programming/ CS majors?
it doesn't look like those for loops are nested. the code just doesn't have them spaced out.
|
Re: Requesting help for programming/ CS majors?
Thanks for the input!
Anyways, I believe we are allowed to use commands that do it for us. And I meant to put in characters, not integers. Afterall, we are input letters, not numbers haha. THis is what I have. It's still wrong, but yeah. #include <iostream> using namespace std; int main() { char name[12]; char i; for(i=0; i<12; i++) name[i] = i; cout << "Please enter your name one letter at a time: "; cin >> name; for(i=0; i<12; i++) cout << "This is letter ["<< i <<"]: " << name[i] << "\n"; int dummy; cin >> dummy; return 0; } Basically what I'm trying to get it to do. IS make it ask me to input one letter. So I would put in letter e. Then it would ask me to input another letter, in which I put "r". So on and so fourth. then once I'm done inputting all the letters, it will take every letter, put it into an array, and make them in alphabetical order. |
Re: Requesting help for programming/ CS majors?
Quote:
you're looking for something like: Code:
char name[12]; |
Re: Requesting help for programming/ CS majors?
I thought characters were referred to as letters? 0_0 So I figured entering in char instead since I'm inputting letters. I guess that doesn't work haha.
|
Re: Requesting help for programming/ CS majors?
on a simple level, characters are basically your letters, yes. the problem is there in your actual definition of the for loop, not in the code inside the loop. once you've already hit
Code:
char i; Code:
i=0; |
Re: Requesting help for programming/ CS majors?
Quote:
|
Re: Requesting help for programming/ CS majors?
It seems like you're confusing the "for" loop as a sort of "for each" loop like the one in C#. In C++ you have to use a standard "for" loop, iterating over the loop i times.
|
Re: Requesting help for programming/ CS majors?
I wrote this in java, shouldn't be too hard to translate into C++. But this takes the name characters into an array until the special character * is input.
Code:
import java.util.Scanner; //same as iostream, just java version Then counting the letters should be as simple as looping an equality statement through your array and keeping counters. |
Re: Requesting help for programming/ CS majors?
If you need more direct help, I could help you through Skype possibly. It'll be easier since I can guide you through one step at a time instead of just giving you code.
|
Re: Requesting help for programming/ CS majors?
Quote:
If you post the code now though, it would help. Then I can skype with you once classes are over? |
Re: Requesting help for programming/ CS majors?
I guess. I'll make a section of code that'll work with the first part of your things you're supposed to do.
|
Re: Requesting help for programming/ CS majors?
Alright, sounds good. Add me on Skype, and I'll accept it once I get home.
|
Re: Requesting help for programming/ CS majors?
see Rushy's post for a full explanation of how you can do these tasks manually. that's your fail-safe.
here's some info for a possible C++ specific shortcut for the alphabetizing task. I have no idea how the sort function works haha, but if you get it down, it could save you some time. http://stackoverflow.com/questions/1...th-char-arrayc and Superfreak, be sure to give yourself time for these assignments! having a "get it done now, learn later" mentality will hurt you in the long run :( edit: actually after staring at that StackOverflow page for a bit I think I get what the parameters for the function are. Code:
char array[] = "zabgqkzg"; array is a pointer to the start of the array, and array+sizeof(array) is a pointer to the first memory address after the array I think? lol |
Re: Requesting help for programming/ CS majors?
Thanks haha. And yeah, right now I'm trying to convert what rushy said, into C++. Not going very well. :/
|
Re: Requesting help for programming/ CS majors?
I went ahead and did steps 1 and 2 in java. you should be able to figure out how to count the letter frequency and make the histogram. Here's my java code:
Code:
import java.util.Scanner; |
Re: Requesting help for programming/ CS majors?
Yeah, I didn't notice rushy's post. His will work perfectly fine if you just change the Java functions to C++ functions like he said.
|
Re: Requesting help for programming/ CS majors?
Quote:
|
All times are GMT -5. The time now is 10:45 PM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution