hello , i ma new in this group and writing over the fact that i have a
small project at hand,i am writing a program which can permit the input
of a text of arbitary lenght,and the number of double vowels must be
determined.
Output:frequenc y of each double vowel ,must be dtermined.
e.g.
Later ,we will see you again
OUTPUT:1xee,1xo u,1xai.
I already wrote one but using the new library string type string,but i
wish to do this for a particular purpose and hence wish to use rather
the c string and functions from <string.h>,
e.g strcpy,....but i am also very new in c so i have not understood how
i can convert the code in that way, i will post the code here and
please welcome any new ideas.
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void scanner(string) ;
bool isVowel(char);
int main(){
string sentence;
cout << "Enter $ to terminate!" <<endl;
do{
cout << "\nEnter the input string: ";
getline(cin,sen tence);
scanner(sentenc e);
}while(sentence != "$");
return 0;
}
void scanner(string s){
int stringSize = s.length();
char current,next;
int count = 0;
int aa,ae,ai,ao,au, ea,ee,ei,eo,eu, ia,ie,ii,io,iu, oa,oe,oi,oo,ou,
ua,ue,ui,uo,uu;
aa = ae = ai = ao = au = 0;
ea = ee = ei = eo = eu = 0;
ia = ie = ii = io = iu = 0;
oa = oe = oi = oo = ou = 0;
ua = ue = ui = uo = uu = 0;
while(count < stringSize){
current = s[count];
if( (count + 1) == stringSize)
break;
next = s[count + 1];
if(isVowel(curr ent) && isVowel(next)){
//a
current = tolower(current );
next = tolower(next);
if( current == 'a' && next == 'a')
aa++;
else if( current == 'a' && next == 'e')
ae++;
else if( current == 'a' && next == 'i')
ai++;
else if( current == 'a' && next == 'o')
ao++;
else if( current == 'a' && next == 'u')
au++;
//e
else if( current == 'e' && next == 'a')
ea++;
else if( current == 'e' && next == 'e')
ee++;
else if( current == 'e' && next == 'i')
ei++;
else if( current == 'e' && next == 'o')
eo++;
else if( current == 'e' && next == 'u')
eu++;
//i
else if( current == 'i' && next == 'a')
ia++;
else if( current == 'i' && next == 'e')
ie++;
else if( current == 'i' && next == 'i')
ii++;
else if( current == 'i' && next == 'o')
io++;
else if( current == 'i' && next == 'u')
iu++;
//o
else if( current == 'o' && next == 'a')
oa++;
else if( current == 'o' && next == 'e')
oe++;
else if( current == 'o' && next == 'i')
oi++;
else if( current == 'o' && next == 'o')
oo++;
else if( current == 'o' && next == 'u')
ou++;
//u
else if( current == 'u' && next == 'a')
ua++;
else if( current == 'u' && next == 'e')
ue++;
else if( current == 'u' && next == 'i')
ui++;
else if( current == 'u' && next == 'o')
uo++;
else /*( current == 'u' && next == 'u')*/
uu++;
count++;
}
else{
count++;
continue;
}
}
int totalVowels = aa + ae + ai + ao + au +
ea + ee + ei + eo + eu +
ia + ie + ii + io + iu +
oa + oe + oi + oo + ou +
ua + ue + ui + uo + uu ;
if(totalVowels == 0){
cout << "No double vowels!" <<endl;
}
if(aa > 0){
cout << aa <<"x "<<"aa";
totalVowels -= aa;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ae > 0){
cout << ae <<"x "<<"ae";
totalVowels -= ae;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ai > 0){
cout << ai <<"x "<<"ai";
totalVowels -= ai;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ao > 0){
cout << ao <<"x "<<"ao";
totalVowels -= ao;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(au > 0){
cout << au <<"x "<<"au";
totalVowels -= au;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ea > 0){
cout << ea <<"x "<<"ea";
totalVowels -= ea;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ee > 0){
cout << ee <<"x "<<"ee";
totalVowels -= ee;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ei > 0){
cout << ei <<"x "<<"ei";
totalVowels -= ei;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(eo > 0){
cout << eo <<"x "<<"eo";
totalVowels -= eo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(eu > 0){
cout << eu <<"x "<<"eu";
totalVowels -= eu;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ia > 0){
cout << ia <<"x "<<"ia";
totalVowels -= ia;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ie > 0){
cout << ie <<"x "<<"ie";
totalVowels -= ie;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ii > 0){
cout << ii <<"x "<<"ii";
totalVowels -= ii;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(io > 0){
cout << io <<"x "<<"io";
totalVowels -= io;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(iu > 0){
cout << iu <<"x "<<"iu";
totalVowels -= iu;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oa > 0){
cout << oa <<"x "<<"oa";
totalVowels -= oa;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oe > 0){
cout << oe <<"x "<<"oe";
totalVowels -= oe;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oi > 0){
cout << oi <<"x "<<"oi";
totalVowels -= oi;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(oo > 0){
cout << oo <<"x "<<"oo";
totalVowels -= oo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ou > 0){
cout << ou <<"x "<<"ou";
totalVowels -= ou;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ua > 0){
cout << ua <<"x "<<"ua";
totalVowels -= ua;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ue > 0){
cout << ue <<"x "<<"ue";
totalVowels -= ue;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(ui > 0){
cout << ui <<"x "<<"ui";
totalVowels -= ui;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(uo > 0){
cout << uo <<"x "<<"uo";
totalVowels -= uo;
if(totalVowels == 0)
cout <<".";
else cout <<", ";
}
if(uu > 0){
cout << uu <<"x "<<"uu"<<". ";
totalVowels -=uu;
}
}
bool isVowel(char c){
return (c == 'a' || c == 'A' || c == 'e' ||
c == 'E' || c == 'i' || c == 'I' || c == 'o' ||
c == 'O' || c == 'u' || c == 'U') ;
} 11 1908
"Prof.Stanl ey" writes: hello , i ma new in this group and writing over the fact that i have a small project at hand,i am writing a program which can permit the input of a text of arbitary lenght,and the number of double vowels must be determined. Output:frequenc y of each double vowel ,must be dtermined.
<snip>
This is not really responsive to your question but are you aware of state
machines? My instincts would be to implement a state machine somehow in
solving this problem, I suspect the code would be much simpler.
> This is not really responsive to your question but are you aware of state machines? My instincts would be to implement a state machine somehow in solving this problem, I suspect the code would be much simpler.
A state machine? Just for capturing double vowels?
I do think OP's code needs significant clean up but a state machine is
an overkill.
As for OP's question: even though it is topical in this group I suspect
you'd get much better answers from comp.lang.c because after all, we are
too close to std::string for too long :-)
Regards,
Ben
benben wrote: A state machine? Just for capturing double vowels?
What do you think a regular expression is? ;-)
--
Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
In article <1147863772.404 018.107550
@j33g2000cwa.go oglegroups.com> , stanley.a.mungw e@uni-
oldenburg.de says... hello , i ma new in this group and writing over the fact that i have a small project at hand,i am writing a program which can permit the input of a text of arbitary lenght,and the number of double vowels must be determined. Output:frequenc y of each double vowel ,must be dtermined.
e.g. Later ,we will see you again
OUTPUT:1xee,1xo u,1xai.
I already wrote one but using the new library string type string,but i wish to do this for a particular purpose and hence wish to use rather the c string and functions from <string.h>, e.g strcpy,....but i am also very new in c so i have not understood how i can convert the code in that way, i will post the code here and please welcome any new ideas.
I see no advantage of a C string over a C++ string in
this case. Then again, you're using the string little
enough that it hardly makes a real difference either way.
[ ... ]
if( current == 'a' && next == 'a') aa++; else if( current == 'a' && next == 'e') ae++;
[ more elided ]
This does not strike me as a particularly efficient
method of doing the job.
I think I'd use something like this:
static char vowels[] = "aeiouy";
const int size = sizeof(vowels);
// Here we depend on the fact that the sizeof a
// string literal is one more than the number of
// characters it contains.
int counts[size][size];
// return 0 to indicate "not a vowel"
// return position among vowels to
// indicate a vowel -- i.e. a=1, e=2, etc.
//
int VowelPos(int ch) {
return strchr(vowels, ch)+1;
}
void scan(char *s) {
int first = 'x'; // must initialize to a non-vowel
int second;
int x, y;
while ((second=*++s)! ='\0') {
x = VowelPos(first) ;
y = VowelPos(second );
++counts[x][y];
first = second;
}
}
Okay, the idea here is fairly simple: instead of using a
separate variable for each count, we use a square matrix.
To keep things a bit simpler, we include an extra row and
an extra column in the matrix. We use those to hold the
counts of any pairs that include any non-vowels
(consonant, punctuation, space, etc.) This saves us from
testing whether things are vowels inside of our loop. In
the loop, we simply read in characters, find their
position among the vowels (or 0 if it's not a vowel) and
increment the appropriate position in our matrix. Each
pair of vowels has a position in the matrix. For your
example above, the resulting matrix would look about like
this:
counts:
a e i o u y
a 0 0 1 0 0 0
e 0 1 0 0 0 0
i 0 0 0 0 0 0
o 0 0 0 0 1 0
u 0 0 0 0 0 0
y 0 0 0 0 0 0
For the moment, I've skipped over column 0 and row 0,
since we're going to ignore them anyway (that's where we
put the counts of anything that included a consonant).
To print out our results, we can use a nested loop,
something like this:
// ignore column 0 and row 0, since that's where we
// put the counts of non-vowels.
for (x=1; x<size; x++)
for (y=1; y<size; y++)
if (counts[x][y] != 0)
std::cout
<< vowels[x-1]
<< vowels[y-1]
<< "\t"
<< counts[x][y];
As for reading the data into a C-style string instead of
a C++ string, the easiest way is probably to use
ifstream::getli ne, something like:
const int max = 4096;
char sentence[max];
cin.getline(sen tence, max);
if (sentence[0] != '$')
scan(sentence);
--
Later,
Jerry.
The universe is a figment of its own imagination.
In article <nXHag.72897$_S 7.24632
@newssvr14.news .prodigy.com>, ph*******@gmail .com says... benben wrote:
A state machine? Just for capturing double vowels?
What do you think a regular expression is? ;-)
Overkill!
--
Later,
Jerry.
The universe is a figment of its own imagination.
Jerry Coffin wrote: > A state machine? Just for capturing double vowels?
What do you think a regular expression is? ;-)
Overkill!
[aeiouy][aeiouy] is overkill? I didn't even need to think about it to type
that in?!
--
Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
In article <dbIag.72902$_S 7.64498
@newssvr14.news .prodigy.com>, ph*******@gmail .com says... Jerry Coffin wrote:
> A state machine? Just for capturing double vowels?
What do you think a regular expression is? ;-)
Overkill!
[aeiouy][aeiouy] is overkill? I didn't even need to think about it to type that in?!
That recognizes the right string, but from there you need
to store the data correctly as well. Admittedly, most
things that support REs also have some sort of
associative array as well. If you were writing this in
AWK or PERL or something on that order, this would almost
certainly be a reasonable way to do things.
OTOH, the OP was talking about doing this in C++, which
doesn't (yet) have any support for REs. In addition, the
OP was (for whatever reason) interested in using C
instead of C++ strings. Using std::map and the regular
expressions out of (say) the once and future TR1 seems
pretty much directly counter to the sort of direction he
seems to want to go.
Given C++ as a starting point: yes, it's overkill.
--
Later,
Jerry.
The universe is a figment of its own imagination.
Jerry Coffin wrote: Given C++ as a starting point: yes, it's overkill.
In some situations, a regex is already available, and in others it is not.
So the reason "C++ sucks" is not a good answer to "why not use a Regex?"
However, the question I answered was whether a state table was overkill.
Because a regex _is_ a state table generator, in a neat little package
behind a useful interface, then it may indeed be slightly less overkill
than writing a state table from scratch!
--
Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
benben wrote: This is not really responsive to your question but are you aware of state machines? My instincts would be to implement a state machine somehow in solving this problem, I suspect the code would be much simpler.
A state machine? Just for capturing double vowels?
I do think OP's code needs significant clean up but a state machine is an overkill.
As for OP's question: even though it is topical in this group I suspect you'd get much better answers from comp.lang.c because after all, we are too close to std::string for too long :-)
He'd have to rewrite the entire program, including all the output
statements that use <iostream> and such before he could post it to clc.
While not popular, the old-style strings are still valid C++. I'll try
to give him some tips directly.
Brian This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: mike420 |
last post by:
THE GOOD:
1. pickle
2. simplicity and uniformity
3. big library (bigger would be even better)
THE BAD:
|
by: Derek Hart |
last post by:
I wish to execute code from a string. The string will have a function name,
which will return a string:
Dim a as string
a = "MyFunctionName(param1, param2)"
I have seen a ton of people discuss how reflection does this, but I cannot
find the syntax to do this. I have tried several code example off of
gotdotnet and other articles. Can somebody please show me the code to do
this?
|
by: Peter Row |
last post by:
Hi all,
Here is my problem:
I have a SQL Server 2000 DB with various NVarChar, NText fields in its
tables.
For some stupid reason the data was inserted into these fields in UTF8
encoding.
However when you retrieve these values into a dataset and ToString() them
|
by: Gregg |
last post by:
Hello all,
I have been banging my head over a problem that I am having reading a
comma seperated file (CSV) that can contain from 1 to 10,000 records.
My code snipit is as follows:
**Start code snipit**
Dim strCustFullName as string
Dim strCustAddr1 as string
|
by: dog |
last post by:
I've seen plenty of articles on this topic but none of them have been
able to solve my problem.
I am working with an Access 97 database on an NT4.0 machine, which has
many Access reports.
I want my users to be able to select a report, click on a command
button on a form, which will then automatically create the report as a
pdf file and save it to the user's machine.
I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
| |
by: Roy |
last post by:
Hi,
I have a problem that I have been working with for a while.
I need to be able from server side (asp.net) to detect that the file i'm
streaming down to the client is saved completely/succsessfully on the
client's computer before updating some metadata on the server (file
downloaded date for instance)
However,
All examples i have tried, and all examples I have found that other people
says works - doesn't work for me :-(
|
by: James Radke |
last post by:
Hello,
We are currently using a user DLL that when working in VB 6.0 has a user
defined type as a parameter.
Now we are trying to use the same DLL from a vb.net application and are
having some problems getting it to work and we don't know why. Basically
the function is accepting the parameters, and then returning an error and
never performing the update.
|
by: Cleo |
last post by:
Hi,
I am trying to call a WebService Method written in Weblogic from VB.NET and
I am getting the following error. I am using SOAP Caal s from VB.NET.
Please find the wsdl file and my code.
Any help would really be appreciated.
Thx
|
by: Lumpierbritches |
last post by:
I have an application my partner wrote that would allow an autoresponse to any
Mapi compliant email that apparently in .Net won't, can someone assist me with
fixing this?
Here is the code:
Utilities Module:
Option Explicit
Option Base 1
|
by: ransoma22 |
last post by:
I developing an application that receive SMS from a connected GSM
handphone, e.g Siemens M55, Nokia 6230,etc through the data cable.
The application(VB.NET) will receive the SMS automatically, process and
output to the screen in my application when a message arrived. But the
problem is how do I read the SMS message immediately when it arrived
without my handphone BeEPINg for new message ? I read up the AT
commands, but when getting down...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |