473,395 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Please,help as soon as you can.

Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help me.

This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of
our text.

I have done Exercise 7 for you: Below you will find the ADT specification
for a string
of characters. It represents slightly more that a minimal string class.

//--------------------------------------------------------------------------
-
#ifndef MyStringH
#define MyStringH
//--------------------------------------------------------------------------
-
typedef char CharType; // Allow for other character types

class String
{
public:
// Constructors and Destructor
String( int capacity = 50 ); // Make empty String with given capacity
String( const String & str ); // Copy str
String( const CharType * str, int capacity = 50 ); // Make str a String
~String();

// Queries
unsigned Length() const { return count_; }
bool IsEmpty() const { return (count_ == 0); }
bool IsFull() const { return count_ == capacity_; }
int IndexOf( const String & str );
String SubString( unsigned start, unsigned count ) const; // Copy out
const CharType * c_str() const;

// Modifiers
CharType & operator[]( int index ) { return string_[index]; } // Unsafe

bool Delete( unsigned start, unsigned count );

bool Insert( unsigned pos, const String & str );

private:
// You supply the private data members
};
//--------------------------------------------------------------------------
-
#endif

Note that this is nearly the header file (*.h) you would use to declare the
class. The private data for the class is missing, but there are a few hints
in the above code to show you what data is required.

The Constructors and Destructor

String( int capacity = 50 );
This constructor creates an empty String with the given capacity. If an
argument is missing for the parameter capacity, it is given the default
value 50 by the compiler.

String( const String & str );
This constructor is the copy constructor. It creates an exact duplicate of
its argument str. This includes duplicating the array of characters owned
by the object str.

String( const CharType * str, int capacity = 50 );
This constructor receives a pointer to a null terminated array of characters
of type CharType, which is set to char in the header file, but could also be
other types. It also receives an optional argument specifying a capacity.
The constructor creates a String object of the given capacity and sets its
internal array of characters equal to the array str by copying the
characters.

The Query Functions

The functions Length(), IsEmpty() and IsFull() return the number of
characters in the String object, whether the String is empty, and whether
the string is full (length = capacity) respectively. Note these functions
are implemented in the class declarations and give you some hints about
other class details.

int IndexOf( const String & str );
This functions returns the zero-based index of its String argument str
within the String object *this that is used to call the function. If str
can not be found as a substring within *this, the value -1 is returned. For
example, String("ab").IndexOf( String("b") ) returns 1.

String SubString( unsigned start, unsigned count ) const;
This function returns a String object, the value of which is the substring
that begins at index position start and contains count characters. The
value given for start must lie within the String object, and if it doesn't
the string String("") is returned. The value of count must not extend
beyond the end of the String object, and if it does then count is truncated
to correspond to the end of the string. For example,
String("ab").SubString( 0, 1 ) returns String("a"),
String("ab").SubString( 0, 3 ) returns String("ab"),
String("ab").SubString( 3, 1 ) returns String("").

const CharType * c_str() const;
This function returns a pointer to a dynamically allocated C++ array of
characters of type CharType. The array is a null terminated string
containing a copy of the characters in its String object. For example,
String("ab").c_str() returns a pointer to "ab". It is the responsibility of
the calling code to delete [ ] the string so returned.

The Modifier Functions

CharType & operator[]( int index ) { return string_[index]; }
The overloaded operator[] returns a reference to the character at position
index which allows individual characters to be read and changed. For
example,
String("abc")[2] = 'a' becomes String("aba"),
CharType ch = String("abc")[2] produces ch == 'a'.
Note that this function is already implemented and provides some hints about
class details.

bool Delete( unsigned start, unsigned count );
Function Delete deletes count characters from the string object that called
the function, starting at index position start. Arguments start and count
obey the same rules as described for function SubString. Use function
SubString to preview the substring that would be deleted. Use function
IndexOf to find a substring to delete.

bool Insert( unsigned pos, const String & str );
Function Insert inserts its second argument at the position index in the
string that called the function. This function may be used to append or
prepend strings to a given string. For example,
String("abd").Insert( 0, "xyz" ) produces String("xyzabd"),
String("abd").Insert( 3, "xyz" ) produces String("abdxyz"),
String("abd").Insert( 2, "c" ) produces String("abcd").

What You Do

Your job is to implement and test this ADT using an array allocated with the
new operator in the constructors and de-allocated with the delete []
operator in the destructor. You will find that three data members will be
sufficient for the job. At a minimum, you must test each function with
enough different arguments to show it works.

You are allowed to define additional helper functions, member functions or
otherwise. For example, the following function allows you to use the <<
operator to display a String.

ostream & operator<<( ostream & os, const String & str )
{
os << str.c_str();
return os;
}

With this function the following works:

String s("My string");
cout << s << '\n';

Also, the following function compares two C-style "strings" up to n
"characters" and returns a + value if s1 > s2, a - value if s1 < s2, and
zero if s1 == s2.

int MemCmp( const CharType * s1, const CharType * s2, unsigned n )
{
// Assume bin op - is defined for type CharType
for ( unsigned c = 0; c < n; ++c )
{
if ( (s1[c] - s2[c]) != 0 )
return (s1[c] - s2[c]); // s1 > or < s2
}
return 0; // s1 == s2
}

When you need a null character of type CharType use this: CharType('\0')

How You Do This
Important: do not attempt to implement this all at once. Start with the
constructors and destructor. Implement them one at a time and use the
functions Length(), IsEmpty() and IsFull() to output the length of an
object, whether the object is empty, and whether the object is full. When
you get correct results for each constructor, you may proceed to the next
phase.

Implement and test function c_str(). This will allow you to output a string
using operator <<.

Use the implemented operator [] to display and then change and display one
or two strings created in the first phase. When all appears correct you may
proceed to the next phase.

Implement and test IndexOf().

Implement and test SubString().

Implement and test Delete().

Implement and test Insert().
Your Grade

Your grade will be based on 1) correctness of your code, 2) good style
(indentation, variable names, etc.), 3) adequate testing, and 4) amount
completed.

It is always better to turn in something rather than nothing. Late papers
are not accepted. Incomplete but timely papers may be improved and
re-submitted within a week.

Failure to attempt 2 or more labs results in failure of the course.


Jul 23 '05 #1
7 2349

Alan Bashy wrote:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help me.

This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text.

I have done Exercise 7 for you: Below you will find the ADT specification for a string
of characters. It represents slightly more that a minimal string class.
//-------------------------------------------------------------------------- -
#ifndef MyStringH
#define MyStringH
//-------------------------------------------------------------------------- -
typedef char CharType; // Allow for other character types

class String
{
public:
// Constructors and Destructor
String( int capacity = 50 ); // Make empty String with given capacity String( const String & str ); // Copy str
String( const CharType * str, int capacity = 50 ); // Make str a String ~String();

// Queries
unsigned Length() const { return count_; }
bool IsEmpty() const { return (count_ == 0); }
bool IsFull() const { return count_ == capacity_; }
int IndexOf( const String & str );
String SubString( unsigned start, unsigned count ) const; // Copy out const CharType * c_str() const;

// Modifiers
CharType & operator[]( int index ) { return string_[index]; } // Unsafe
bool Delete( unsigned start, unsigned count );

bool Insert( unsigned pos, const String & str );

private:
// You supply the private data members
};
//-------------------------------------------------------------------------- -
#endif

Note that this is nearly the header file (*.h) you would use to declare the class. The private data for the class is missing, but there are a few hints in the above code to show you what data is required.

The Constructors and Destructor

String( int capacity = 50 );
This constructor creates an empty String with the given capacity. If an argument is missing for the parameter capacity, it is given the default value 50 by the compiler.

String( const String & str );
This constructor is the copy constructor. It creates an exact duplicate of its argument str. This includes duplicating the array of characters owned by the object str.

String( const CharType * str, int capacity = 50 );
This constructor receives a pointer to a null terminated array of characters of type CharType, which is set to char in the header file, but could also be other types. It also receives an optional argument specifying a capacity. The constructor creates a String object of the given capacity and sets its internal array of characters equal to the array str by copying the
characters.

The Query Functions

The functions Length(), IsEmpty() and IsFull() return the number of
characters in the String object, whether the String is empty, and whether the string is full (length = capacity) respectively. Note these functions are implemented in the class declarations and give you some hints about other class details.

int IndexOf( const String & str );
This functions returns the zero-based index of its String argument str within the String object *this that is used to call the function. If str can not be found as a substring within *this, the value -1 is returned. For example, String("ab").IndexOf( String("b") ) returns 1.

String SubString( unsigned start, unsigned count ) const;
This function returns a String object, the value of which is the substring that begins at index position start and contains count characters. The value given for start must lie within the String object, and if it doesn't the string String("") is returned. The value of count must not extend beyond the end of the String object, and if it does then count is truncated to correspond to the end of the string. For example,
String("ab").SubString( 0, 1 ) returns String("a"),
String("ab").SubString( 0, 3 ) returns String("ab"),
String("ab").SubString( 3, 1 ) returns String("").

const CharType * c_str() const;
This function returns a pointer to a dynamically allocated C++ array of characters of type CharType. The array is a null terminated string
containing a copy of the characters in its String object. For example, String("ab").c_str() returns a pointer to "ab". It is the responsibility of the calling code to delete [ ] the string so returned.

The Modifier Functions

CharType & operator[]( int index ) { return string_[index]; }
The overloaded operator[] returns a reference to the character at position index which allows individual characters to be read and changed. For example,
String("abc")[2] = 'a' becomes String("aba"),
CharType ch = String("abc")[2] produces ch == 'a'.
Note that this function is already implemented and provides some hints about class details.

bool Delete( unsigned start, unsigned count );
Function Delete deletes count characters from the string object that called the function, starting at index position start. Arguments start and count obey the same rules as described for function SubString. Use function SubString to preview the substring that would be deleted. Use function IndexOf to find a substring to delete.

bool Insert( unsigned pos, const String & str );
Function Insert inserts its second argument at the position index in the string that called the function. This function may be used to append or prepend strings to a given string. For example,
String("abd").Insert( 0, "xyz" ) produces String("xyzabd"),
String("abd").Insert( 3, "xyz" ) produces String("abdxyz"),
String("abd").Insert( 2, "c" ) produces String("abcd").

What You Do

Your job is to implement and test this ADT using an array allocated with the new operator in the constructors and de-allocated with the delete []
operator in the destructor. You will find that three data members will be sufficient for the job. At a minimum, you must test each function with enough different arguments to show it works.

You are allowed to define additional helper functions, member functions or otherwise. For example, the following function allows you to use the << operator to display a String.

ostream & operator<<( ostream & os, const String & str )
{
os << str.c_str();
return os;
}

With this function the following works:

String s("My string");
cout << s << '\n';

Also, the following function compares two C-style "strings" up to n
"characters" and returns a + value if s1 > s2, a - value if s1 < s2, and zero if s1 == s2.

int MemCmp( const CharType * s1, const CharType * s2, unsigned n )
{
// Assume bin op - is defined for type CharType
for ( unsigned c = 0; c < n; ++c )
{
if ( (s1[c] - s2[c]) != 0 )
return (s1[c] - s2[c]); // s1 > or < s2
}
return 0; // s1 == s2
}

When you need a null character of type CharType use this: CharType('\0')
How You Do This
Important: do not attempt to implement this all at once. Start with the constructors and destructor. Implement them one at a time and use the functions Length(), IsEmpty() and IsFull() to output the length of an
object, whether the object is empty, and whether the object is full. When you get correct results for each constructor, you may proceed to the next phase.

Implement and test function c_str(). This will allow you to output a string using operator <<.

Use the implemented operator [] to display and then change and display one or two strings created in the first phase. When all appears correct you may proceed to the next phase.

Implement and test IndexOf().

Implement and test SubString().

Implement and test Delete().

Implement and test Insert().
Your Grade

Your grade will be based on 1) correctness of your code, 2) good style (indentation, variable names, etc.), 3) adequate testing, and 4) amount completed.

It is always better to turn in something rather than nothing. Late papers are not accepted. Incomplete but timely papers may be improved and
re-submitted within a week.

Failure to attempt 2 or more labs results in failure of the course.


we ARE NOT a homework group!!!!
I have seen certain website where you can submit your assignments, and
they don't charge a great deal. Good Luck!

Jul 23 '05 #2
Alan Bashy wrote:

[homework stuff snipped]

To quote the FAQ:

"If I did your homework for you, then you might pass your class without
learning how to write a program like this. Then you might graduate and
get your degree without learning how to write a program like this. You
might become a professional programmer without knowing how to write a
program like this. Someday you might work on a project with me without
knowing how to write a program like this. Then I would have to do you
serious bodily harm." [Thanks to Jack Klein]

--
Regards,

Karsten
Jul 23 '05 #3
This might help:

---- CODE ----

#include <iostream>

using namespace std;

int main() {
cout << "Do your own homework.\n";
return 0;
}

---- /CODE ----
Jul 23 '05 #4
Alan Bashy wrote:
Your Grade

Your grade will be based on 1) correctness of your code, 2) good style
(indentation, variable names, etc.), 3) adequate testing, and 4) amount
completed.


That was a nice assignment that the OP must do by himself, however I
think (3) is too ambiguous (but very common style in assignments).
What kind of testing should one provide in such homework?


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5
"Alan Bashy" writes:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help me.

This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of
our text.

I have done Exercise 7 for you: Below you will find the ADT specification
for a string
of characters. It represents slightly more that a minimal string class.

//--------------------------------------------------------------------------
-
#ifndef MyStringH
#define MyStringH
//--------------------------------------------------------------------------
-
typedef char CharType; // Allow for other character types

class String
{
public:
// Constructors and Destructor
String( int capacity = 50 ); // Make empty String with given capacity
[elided]
Your job is to implement and test this ADT using an array allocated with
the
new operator in the constructors and de-allocated with the delete []
operator in the destructor. You will find that three data members will be
sufficient for the job.


It appears he wants you to make a "Pascal style" string, which is able to
store a value of binary zero for a character. So, something like this:

private:
char* ca; // character array. allocated via new.
// Which means there must also be a destructor to release
the space.
int sz_max; // 50 for default
int sz_curr; // 0 for default

Now write the first contructor.

The assignment is very chatty, he's trying to be nice. :-( Try to
extract the essence, one chunk at a time, as I have done here.
Jul 23 '05 #6
Alan Bashy wrote:

Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help me.
Hmm. The only question you are asking is: "Can someone do this for me"?
I doubt that somebody will do this in this group.

But: If you try to implement one of the constructors (don't write all
of them in one rush. Write one and test it) and have problems with it,
you can always come back and ask specific questions. And then you will
see that the group is more then willing to help.
In fact the rule is: If you show signs of an attempt of yourself to solve
your problem, you will get plenty of help. If you show no such sign, nobody
is going to help.

Your instructor even gave you a hint on how to proceed, which is IMHO
very good advice. Why don't you follow it?

How You Do This
Important: do not attempt to implement this all at once. Start with the
constructors and destructor. Implement them one at a time and use the
functions Length(), IsEmpty() and IsFull() to output the length of an
object, whether the object is empty, and whether the object is full. When
you get correct results for each constructor, you may proceed to the next
phase.

Implement and test function c_str(). This will allow you to output a string
using operator <<.

Use the implemented operator [] to display and then change and display one
or two strings created in the first phase. When all appears correct you may
proceed to the next phase.

Implement and test IndexOf().

Implement and test SubString().

Implement and test Delete().

Implement and test Insert().


--
Karl Heinz Buchegger
kb******@gascad.at
Jul 23 '05 #7
On Thu, 10 Feb 2005 01:15:12 GMT, "Alan Bashy" <ba*****@hotmail.com>
wrote:
Please, guys, In need help with this. It is due in the next week.
In most jobs you are required to be able to manage you own time
effectively. Now you know why. It is certainly a skill worth having.
Please, help me to implement the functions in this programm especially the first
three constructor.
Certainly we will help, but *only* if you show us what you have done
so far. Show us what you got for the data members of the class and
what you have done for the first constructor. Explain which parts you
are having a problem with.
[Snip]

How You Do This
Important: do not attempt to implement this all at once. Start with the
constructors and destructor. Implement them one at a time and use the
functions Length(), IsEmpty() and IsFull() to output the length of an
object, whether the object is empty, and whether the object is full. When
you get correct results for each constructor, you may proceed to the next
phase.
This is good advice. I suggest that you follow it. Do the work in
small bite-sized pieces. Even experts work this way, it is just that
they can take bigger bites than beginners. Work on one function at a
time. Implement one of the constructors, if you get problems then
show us your code and we will help. When you think it is working then
test it with different inputs. Repeat for the other constructors and
the destructor. Then implement Length(), IsEmpty() and IsFull() one
at a time. Test each one as you write it to make sure that it works.
You can hand in your testing code with the assignment as it is part of
the work you are told to do.
[Snip]

Your Grade

Your grade will be based on 1) correctness of your code, 2) good style
(indentation, variable names, etc.), 3) adequate testing, and 4) amount
completed.

It is always better to turn in something rather than nothing. Late papers
are not accepted. Incomplete but timely papers may be improved and
re-submitted within a week.


Take note of these two paragraphs, especially the second.
rossum

--

The ultimate truth is that there is no Ultimate Truth
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Robert Hathaway | last post by:
COMP.OBJECT FAQ Version II Beta now Available http://www.objectfaq.com/oofaq2 ================================================== - Latest Important Information on Object Technology - What's New...
0
by: Bennett F. Dill | last post by:
Thanks for reading. I'm having problems with cookies from asp to asp.net and back! It seems like I can set a cookie in asp.net fine, and alter it at will, as soon as asp touches it, asp.net...
4
by: Corey Dyke | last post by:
K here's what happened. For my English project at DeVry, I had to design a website for a company of my choice. So since my dad has been after me for years to do one for him, I decided to finally...
21
by: salad | last post by:
Thanks for reading this post and wasting your time. I was thinking about writing about the PCDatasheet vs The Pussyfarts war. The pussyfarts, as near as I can tell, have little to offer this...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
2
by: sujithvaddi | last post by:
Hello sir/madam, This is Sujith. I am working on an online form with user authentication page using ASP and using MS access database. So i am done and everything is ok when I am doing on my...
4
by: king1986 | last post by:
hello everybody, I'm a new member here, and I'm happy to be with you. Please I'm a student and I need to finish my project as soon as possible, but I have a problem. Actually, my project is to do...
1
by: MasterMind | last post by:
Please Help me as soon as possible. I do work on threads in C#. I stuck in a problem. The problem is... I want to generate message on the some specific time e.g I want to generate a message...
5
by: =?Utf-8?B?TWljaGFlbA==?= | last post by:
Hello, I am in serious need of help. I have an ASP.NET application written in C#. I have a page that processes a file on the web server. The page uses a class I created and stored in the AppCode...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
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,...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.