Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 10-18-09   #1 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default Arrays in C++

So i'm learning array single dimensional and i have this problem to do but i don't know how to start it.

PHP Code:
Write a function that counts the occurrence of each letter in the string using the following header:

void count (const char s[], int counts [], int size)

where size is the seize of the counts array. In this case, it is 26. Letters are not case-sensitiveand a are counted as a.

Write a test program that reads a stringinvokes the count function, and displays the no-zero counts.

Example

Enter a string
Welcome to New York!
c1 times
e
3 times
k
1 times
l
1 times
m
1 times
n
1 times
o
3 times
r
1 times
t
1 times
w
2 times
y
1 times 
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 10-18-09   #2 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,925

Rep: 86 B-80 is acknowledged by some
Unique Rep: 76
Trader Rating: 0
Default

Quote:
Originally Posted by Mikey122687 View Post
So i'm learning array single dimensional and i have this problem to do but i don't know how to start it.

PHP Code:
Write a function that counts the occurrence of each letter in the string using the following header:

void count (const char s[], int counts [], int size)

where size is the seize of the counts array. In this case, it is 26. Letters are not case-sensitiveand a are counted as a.

Write a test program that reads a stringinvokes the count function, and displays the no-zero counts.

Example

Enter a string
Welcome to New York!
c1 times
e
3 times
k
1 times
l
1 times
m
1 times
n
1 times
o
3 times
r
1 times
t
1 times
w
2 times
y
1 times 
string input;

int counts[26];
const char s[] = {'A','B',ect......};

cin >> input;

int size = input.size();
for(int count = 0; count<input.size(); count++){

for(int i = 0; i<26; i++)
{
if(input.substr(count, 1).toUpperCase() == s[i]){
counts[i]++;
i=26;
}
}
}
for(int l = 0; l<26; l++)
{
cout<<s[l]<<": "<<counts[l]<<" times"<<endl;
}
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Windows xp
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058
B-80 is offline   Reply With Quote
Old 10-18-09   #3 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

Hmm, thanks for posting but i can't use the input.substr i haven't learn it yet or is that written a different way?
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 10-18-09   #4 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,925

Rep: 86 B-80 is acknowledged by some
Unique Rep: 76
Trader Rating: 0
Default

what string methods do you know?

charAt() is another you can use.
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Windows xp
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058
B-80 is offline   Reply With Quote
Old 10-18-09   #5 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

The regular one lol. The most basic basic string. I mean i can use C-string, but thats about it.
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 10-19-09   #6 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,925

Rep: 86 B-80 is acknowledged by some
Unique Rep: 76
Trader Rating: 0
Default

Quote:
Originally Posted by Mikey122687 View Post
The regular one lol. The most basic basic string. I mean i can use C-string, but thats about it.
yeah, cstring is what i am using too. but cstring has built in methods like size(), substr(), charAt().
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Windows xp
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058
B-80 is offline   Reply With Quote
Old 4 Weeks Ago   #7 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

I still need help on this if anyone could help me
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Old 4 Weeks Ago   #8 (permalink)
Overclocker
 
B-80's Avatar
 
intel nvidia

Join Date: Oct 2006
Location: Levittown,PA / Penn State
Posts: 1,925

Rep: 86 B-80 is acknowledged by some
Unique Rep: 76
Trader Rating: 0
Default

Quote:
Originally Posted by Mikey122687 View Post
I still need help on this if anyone could help me
dude I gave you an answer. you can use substr or charat, trust me. They are built into the cstring class. It is part of cstring. IDK how much you know about programming. Why don't you ask your teacher what method she wants you to use?

Also a "thanks for your help" would be nice here and there. instead of just completely disregarding what is most likely the answer to your problem.
__________________

Aumotocnic"An unfortunate member of the overclock.net insomnia club"

-- / T_he Rad / iohead F_a/n Club_--

Crucial Ballistix Club

System: The Mediocre Guy
CPU
E7200 @ 3.8ghz
Motherboard
Gigabyte P45 DS3
Memory
4GB Corsair XMS2
Graphics Card
Geforce 8800 GTS (600/900)
Hard Drive
250 gb hitachi Deskstar + 120gb Seagate
Power Supply
PC Power & Cooling Silencer 750 Quad
Case
Aspire X-Cruiser Black
CPU cooling
Zalman 9700
GPU cooling
Stock
OS
Windows xp
Monitor
ViewSonic Optiquest 20.1 inch 1650x1058
B-80 is offline   Reply With Quote
Old 4 Weeks Ago   #9 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

Quote:
Originally Posted by Mikey122687 View Post
Hmm, thanks for posting but i can't use the input.substr i haven't learn it yet or is that written a different way?
Quote:
Originally Posted by B-80 View Post
dude I gave you an answer. you can use substr or charat, trust me. They are built into the cstring class. It is part of cstring. IDK how much you know about programming. Why don't you ask your teacher what method she wants you to use?

Also a "thanks for your help" would be nice here and there. instead of just completely disregarding what is most likely the answer to your problem.
K first off, i did say thanks.

Second, i'm very new to this so telling me stuff like substr, charat, is like speaking Korean to me. I clearly don't know what it mean.

And how would i put it so it would run?

I did

PHP Code:
#include <iostream>
#include <cmath>

using namespace std;

int main() 
and then put ur code in and it won't run


PHP Code:
#include <iostream>
#include <ctime>
#include <cmath>

using namespace std;

int main ()

{
    

string input;

int counts[26];
const 
char s[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

cin >> input;

int size input.size();
for(
int count 0count<input.size(); count++){

for(
int i 0i<26i++)
{
if(
input.substr(count1).toUpperCase() == s[i]){
counts[i]++;
i=26;
}
}
}
for(
int l 0l<26l++)
{
cout<<s[l]<<": "<<counts[l]<<" times"<<endl;




return 
0;

__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD

Last edited by Mikey122687 : 4 Weeks Ago at 08:18 PM
Mikey122687 is offline   Reply With Quote
Old 4 Weeks Ago   #10 (permalink)
Intel Overclocker
 
intel ati

Join Date: Oct 2004
Posts: 5,626

Rep: 238 Mikey122687 is acknowledged by manyMikey122687 is acknowledged by manyMikey122687 is acknowledged by many
Unique Rep: 176
FAQs Submitted: 2
Hardware Reviews: 5
Trader Rating: 48
Default

what im confused is this

PHP Code:
if(input.substr(count1).toUpperCase() == s[i]) 
You see how it says ".toUpperCase()" I dont know what the (.) means. I have no clue what it stands for or what it does.

I can't ask for help because my professor isn't teaching us anything. All he ever say is "read the book" and the whole class is simply learning on our own. I have to pretty much learn C++ by myself. Whenever i ask him for help, he told me to go read the book. And i did, but it doesn't mean i get all the materials.
__________________


System: Main Rig
CPU
Intel C2Q 6600
Motherboard
DFI LP UT P35-T2R
Memory
GSkill F2-6400CL5D-4GBPQ
Graphics Card
Diamond 4870 1GB
Hard Drive
WD Raptor 74GB RAID0
Sound Card
Creative XFi Fatal1ty FPS
Power Supply
Silverstone Zeus 850W
Case
Lian Li V2000B
CPU cooling
TRUE 120
OS
Windows Vista Ultimate x64
Monitor
SAMSUNG 2253BW Black 22" LCD
Mikey122687 is offline   Reply With Quote
Reply


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



All times are GMT -5. The time now is 04:39 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.16725 seconds with 8 queries