hi..
im trying to build a program using arrays to do the following things:
1- convert a digital number to binary using mathematical operators by using the function void binaryConversio nUsingArithemat icOperators(uns igned long)
2- convert a digital number to binary using bitwise operators by using the function void binaryConversio nUsingBitwiseOp erators(unsigne d long)
3- check if the word is a palindrome using iteration by using this function
void bool isPalindromeUsi ngIteration(str ing)
4- check if the word is a palindrome using recursion by using this function
void bool isPalindromeUsi ngRecursion(str ing)
here is what i wrote:
code: - #include<iostream>
-
#include<string>
-
#include<cctype>
-
using std::string;
-
using std::cout;
-
using std::cin;
-
using std::endl;
-
-
// Here are some function declarations
-
-
unsigned short getMenuSelection( );
-
void binaryConversionUsingArithmeticOperators(unsigned long);
-
void binaryConversionUsingBitwiseOperators (unsigned long);
-
void isPalindromeUsingIteration(string);
-
void isPalindromeUsingRecursion(string);
-
-
// Utilityfunctions declarations
-
void initializeArray(unsigned short[],int);
-
void initializeArray(string[],int);
-
void printBinary(unsigned short[],int);
-
void printBinary(string[],int);
-
-
int main()
-
{
-
unsigned short choice;
-
do
-
{
-
choice = getMenuSelection();
-
-
cout <<"You chose Menu Option #"<<choice<<endl ;
-
switch(choice)
-
{
-
case 1 :
-
unsigned long a;
-
cout<<" Please enter an integer " ;
-
cin>>a ;
-
binaryConversionUsingArithmeticOperators(a);
-
break ;
-
case 2 :
-
cout<<" Please enter an integer " ;
-
cin >>a ;
-
binaryConversionUsingBitwiseOperators(a) ;
-
break ;
-
case 3 :
-
string b;
-
cout<<"Please enter a string ";
-
cin>>b;
-
isPalindromeUsingIteration(b);
-
break;
-
case 4:
-
string b;
-
cout<<"Please enter a string ";
-
cin>>b;
-
isPalindromeUsingIteration(b);
-
break;
-
case 5:
-
break;
-
default:
-
cout<<"you should never get here\a\a\a\a!!!";
-
}
-
}while(choice != 5);
-
cout<<"you choose to quit\a\a\a"<<endl;
-
return 0;
-
}
-
-
//function definitions
-
unsigned short getMenuSelection()
-
{
-
unsigned short selection=0;
-
do
-
{
-
cout<<"-1- Binary Conversion using Arithmetic Operators"<<endl;
-
cout<<"-2- Binary Conversion using Bitwise Operators"<<endl;
-
cout<<"-3- Testing for Palindroms Using Iteration"<<endl;
-
cout<<"-4- Testing for Palindroms Using Recursion"<<endl;
-
cout<<"-5- Quit"<<endl;
-
cout<<"please enter your selection <1-5>:"<<endl;
-
cin>>selection;
-
}
-
while(selection<1 || selection>5);
-
return selection;
-
}
-
void binaryConversionUsingArthematicOperators(unsigned long x)
-
{
-
unsigned short binaryDigit[100],
-
numberOfDigits=0;
-
initializeArray(binaryDigit,100);
-
do
-
{
-
binaryDigit[numberOfDigits++]=x%2;
-
x=x/2;
-
}while(x!=0);
-
printBinary(binaryDigit,numberOfDigits);
-
}
-
-
void binaryConversionUsingBitwiseOperator(unsigned long x)
-
{
-
unsigned short binaryDigit [100],
-
numberOfDigits=0;
-
initializeArray(binaryDigit , 100);
-
do
-
{
-
binaryDigit[numberOfDigits++]=x&1;
-
x=x>>1;
-
}while(x!=0);
-
printBinary(binaryDigit, numberOfDigits);
-
}
-
-
-
void isPalindromeUsingIteration(string y)
-
{
-
while (length>1)
-
{
-
if ( y[] != [y + length - 1])
-
{
-
return false;
-
}
-
++y;
-
length=length-2;
-
}
-
return true;
-
}
-
void isPalindromeUsingRecursion(string y)
-
{
-
if ( length<2 )
-
{
-
return true;
-
}
-
else
-
{
-
if ( y[] != [y + length - 1])
-
{
-
return false;
-
}
-
else
-
{
-
return ispalindromeUsingRecursion(string y+1);
-
}
-
}
-
-
}
-
//utality function definitions
-
void initializeArray (unsigned short a[], int size)
-
{
-
for(int i=0;i<size; i++)
-
a[i]=0;
-
}
-
-
void printBinary(unsigned short a[], int size)
-
{
-
for(int i=size-1; i>=0; i--)
-
cout<<a[i];
-
cout<<endl;
-
}
-
void initializeArray (string b[], int length)
-
{
-
for(int i=0;i<length; i++)
-
b[i]=b;
-
}
-
-
void printBinary(string b[], int length)
-
{
-
for(int i=length-1; i>=0; i--)
-
cout<<b[i];
-
cout<<endl;
-
}
but there are 22 errors!!! i really need some help here..
1 1330 Banfa 9,065
Recognized Expert Moderator Expert
Comments in bold - #include<iostream>
-
#include<string>
-
#include<cctype>
-
using std::string;
-
using std::cout;
-
using std::cin;
-
using std::endl;
-
-
// Here are some function declarations
-
-
unsigned short getMenuSelection( );
-
void binaryConversionUsingArithmeticOperators(unsigned long);
-
void binaryConversionUsingBitwiseOperators (unsigned long);
-
void isPalindromeUsingIteration(string);
-
void isPalindromeUsingRecursion(string);
-
-
// Utilityfunctions declarations
-
void initializeArray(unsigned short[],int);
-
void initializeArray(string[],int);
-
void printBinary(unsigned short[],int);
-
void printBinary(string[],int);
-
-
int main()
-
{
-
unsigned short choice;
-
do
-
{
-
choice = getMenuSelection();
-
-
cout <<"You chose Menu Option #"<<choice<<endl ;
-
switch(choice)
-
{
-
case 1 :
- /* Declaration of data in a switch statement is ill advised
-
at best, it only works here because unsigned long is a
-
basic type, i.e. part of the base language, unlike ... */
-
unsigned long a;
-
cout<<" Please enter an integer " ;
-
cin>>a ;
-
binaryConversionUsingArithmeticOperators(a);
-
break ;
-
case 2 :
-
cout<<" Please enter an integer " ;
-
cin >>a ;
-
binaryConversionUsingBitwiseOperators(a) ;
-
break ;
-
case 3 :
- /* ... here. string is not a basic type. It is a class and requires
-
constructing. You have declared string twice, once here and
-
once in case 4. However these are in the same code block so
-
you have multiply defined the variable in this code block and an
-
error is produced. Not only that but if you remove the declaration
-
in 4 then although the multiply defined error will go away but you
-
would be trying to use the variable without having called the
-
constructor, a BIG mistake. You could create some artifical code
-
blocks by just adding braces insice your case statements but
-
all in all the best thing to do is NOT DECLARE DATA IN A
-
SWITCH. Declare it before the switch.*/
-
string b;
-
cout<<"Please enter a string ";
-
cin>>b;
-
isPalindromeUsingIteration(b);
-
break;
-
case 4:
-
string b;
-
cout<<"Please enter a string ";
-
cin>>b;
-
isPalindromeUsingIteration(b);
-
break;
-
case 5:
-
break;
-
default:
-
cout<<"you should never get here\a\a\a\a!!!";
-
}
-
}while(choice != 5);
-
cout<<"you choose to quit\a\a\a"<<endl;
-
return 0;
-
}
-
-
//function definitions
-
unsigned short getMenuSelection()
-
{
-
unsigned short selection=0;
-
do
-
{
-
cout<<"-1- Binary Conversion using Arithmetic Operators"<<endl;
-
cout<<"-2- Binary Conversion using Bitwise Operators"<<endl;
-
cout<<"-3- Testing for Palindroms Using Iteration"<<endl;
-
cout<<"-4- Testing for Palindroms Using Recursion"<<endl;
-
cout<<"-5- Quit"<<endl;
-
cout<<"please enter your selection <1-5>:"<<endl;
-
cin>>selection;
-
}
-
while(selection<1 || selection>5);
-
return selection;
-
}
-
- /* This function does not have the same name as the one
-
declared and called */
-
void binaryConversionUsingArthematicOperators(unsigned long x)
-
{
-
unsigned short binaryDigit[100],
-
numberOfDigits=0;
-
initializeArray(binaryDigit,100);
-
do
-
{
-
binaryDigit[numberOfDigits++]=x%2;
-
x=x/2;
-
}while(x!=0);
-
printBinary(binaryDigit,numberOfDigits);
-
}
-
- /* This function does not have the same name as the one
-
declared and called */
-
void binaryConversionUsingBitwiseOperator(unsigned long x)
-
{
-
unsigned short binaryDigit [100],
-
numberOfDigits=0;
-
initializeArray(binaryDigit , 100);
-
do
-
{
-
binaryDigit[numberOfDigits++]=x&1;
-
x=x>>1;
-
}while(x!=0);
-
printBinary(binaryDigit, numberOfDigits);
-
}
-
-
-
void isPalindromeUsingIteration(string y)
-
{
- /* The variable length is used without being without defined. */
- /* Logical appears to be incorrectly copied from isPalindromeUsingRecursion. */
-
while (length>1)
-
{
-
if ( y[] != [y + length - 1])
-
{
- /* Attempt to return a value from a void function */
-
return false;
-
}
-
++y;
-
length=length-2;
-
}
- /* Attempt to return a value from a void function */
-
return true;
-
}
-
void isPalindromeUsingRecursion(string y)
-
{
- /* The variable length is used without being without defined. */
-
if ( length<2 )
-
{
- /* Attempt to return a value from a void function */
-
return true;
-
}
-
else
-
{
- /* Syntax is wrong, this should be comparing the first and last
-
character in the string y. */
-
if ( y[] != [y + length - 1])
-
{
- /* Attempt to return a value from a void function */
-
return false;
-
}
-
else
-
{
- /* string y+1 is not a valid expression to provide a parameter.
-
An expression returning the string y with the first and last
-
characters removed is required, look up string::substr() */
-
return ispalindromeUsingRecursion(string y+1);
-
}
-
}
-
-
}
-
//utality function definitions
-
void initializeArray (unsigned short a[], int size)
-
{
-
for(int i=0;i<size; i++)
-
a[i]=0;
-
}
-
-
void printBinary(unsigned short a[], int size)
-
{
-
for(int i=size-1; i>=0; i--)
-
cout<<a[i];
-
cout<<endl;
-
}
-
void initializeArray (string b[], int length)
-
{
-
for(int i=0;i<length; i++)
- /* b[i] and b must (by definition) be different types so an assignment
-
between them is unlikely to work. */
-
b[i]=b;
-
}
-
-
void printBinary(string b[], int length)
-
{
-
for(int i=length-1; i>=0; i--)
-
cout<<b[i];
-
cout<<endl;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: uli2003wien |
last post by:
Dear group,
PASS (SQL-Server user group) is about to start founding a branch in
Vienna. I went to SQLCON and met some guys from the German PASS group
and decided to become a member of PASS, decided to look for other
individuals to take part in an Austrian branch of PASS based in Vienna,
so whoever is interested may take a look at
http://www.sqlpass.de/Default.aspx?tabid=191 in order to get to contact
me to get things going....
|
by: orshov |
last post by:
Hi there,
Please take a look at the new internet program that
I recently joined. They give out Free Internet resources
delivered to your email box daily.
Not only is it FREE, but you Get Paid as well! You'll
Earn $10 Just For Signing Up...FREE!
I think, it would be best if you just take a look at it
|
by: zalzon |
last post by:
Do I have to use char * string and then malloc memory to it?
But malloc(size) can only gurantee that size is allocated. What if the
string is more than size?
Is there any way to find the size of the string before taking it in and
THEN malloc the needed amount?
I'm in a rut, help me please :(
|
by: Rajat Tandon |
last post by:
Hello there,
I am relatively new to the newsgroups and C#. I have never been disappointed
with the groups and always got the prompt replies to my queries.This is yet
another strange issue, I am facing. Please please help me to solve this as
soon as possible.
So here we go ...
I am not able to take the screen shot of the windows form based "Smart
|
by: Giovane Calabrese |
last post by:
( aspx + vb )
hi everyone !
I really need make that function work !
im brazilian , and i want to make a multilanguage system ,
that function above must look at all ASPX take the labels
ID and send as a parameter
,... so Please , help me ,.. cause it doest work !
'----------------------------------------------------------
--------------
| |
by: Giovane Calabrese |
last post by:
ok. im try to make a multilanguage system based on that
tutorial :
http://www.123aspx.com/redir.aspx?res=29112
in my aspx pages all text are in labels , and i want to
take the name labels ( in one loop ) and for each label
take on the XML document the right(in the right language)
Value (text).
|
by: Paw |
last post by:
Greetings.
I use asp.
what I need is is when a visitor comes to the site, I need it to check
the host name. if "www.hometowndigest.com" is the host, then check a
folder named "something" and if the folder does not exsist, create
folder "www" and then copy folder "temp" and its contents.
If the folder "www" is there, look in it, check to see if the files in
folder "temp" are in there, if not, copy the files that are not from
folder...
|
by: Ian Davies |
last post by:
Hello
Needing help with a suitable solution.
I have extracted records into a table under three columns 'category',
'comment' and share (the category column also holds the index no of the
record in a hidden field)
I wish the user to be able to edit the data in the table, so I have
extracted the records into hiddenfield, textareas, dropdown list and
checkbox so that they can make changes.
I named these elements as arrays and wish to run an...
|
by: watches0958 |
last post by:
With today's fashion trends in women's clothing, it can take more
effort to dress for success every day, than to get the job in the
first place.
When you're working every day, you have different roles. You may be
meeting clients, or working at a desk, or going from the office to a
business event. One business outfit doesn't work for every occasion
any more.
Here are 3 tips for dressing for success in 2008
|
by: alireza6485 |
last post by:
Hi,
Could you please rewrite the program for me?I tried my best and the program still does not do what it has to do.
I have to write a code that generates random speed and distance .it ask the user for angle and start calculating the vertical and horizantal positions.
when the vertical position gets negative program should stop and check the horizantal position and print out different messeges based on the value of the horizantal speed.
...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |