473,785 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADT string

4 New Member
The assignment was as follows:
A character string can be implemented as a linked list of characters. Implement a C++ ADT called Newstring that uses linked lists to implement the following string operations:

display()
// display private data on standard output

length()
// returns the length of string

concatenate(New string)
// copies contents of parameter Newstring onto the end of private
// data; does not merely make the last node of the private data
// point to the first node of Newstring object

concatenate(cha r)
// concatenates a single char onto the end of the private data

substring(Newst ring)
// returns true if Newstring object is a substring of the private
// data of the ADT and false otherwise

In all cases string refers to the private data of your ADT. In implementing this ADT, you may want to write additional, private methods to assist the others. Write a short program to test your ADT. You should have a minimum of three files for this project: a header file for the ADT, an implementation file for the ADT, and a file that uses the ADT.


I am having problems getting the length and substring function to work. Please help. The name of each file is listed above each file. The following is what I have done so far:


Newstring.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include "Newstring. h"
using std::endl;
using std::cout;

void main(void)
{
Newstring title("The wages of sins is death");
Newstring lesson ("The gift of god is eternal life");

title.length(ti tle);
title.display() ;
title.concatena te(" save me!");
title.display() ;

lesson.length() ;
lesson.display( );
lesson.concaten ate("s");
lesson.display( );
bool substring();
}


Newstring.h
#ifndef TEST_H
#define TEST_H

class Newstring
{
public:
Newstring (char *); //constructor
int length(void);
void concatenate(cha r *);
void concatenate(cha r);
void display(void);
bool substring (char);
private:
char data[256];
int length;
};
#endif


Newstring1.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include "Test.h"

using std::endl;
using std::cout;

Newstring::News tring(char *str)
{
strcpy_s(data, str);
}

void Newstring::leng th(void)
{
int len = 0;
int i = 0;

while (data[i] != NULL)
{
len++;
i++;
}
cout << "The length of the Newstring is " << length <<endl;
}

void Newstring::conc atenate (char *str)
{
strcat(data, str);
}

void Newstring::disp lay(void)
{
cout << data <<endl;
length(data);
}
Jun 5 '07 #1
7 8280
Savage
1,764 Recognized Expert Top Contributor
I don't see data declaration,wha t is it?

A array of chars?

Savage
Jun 5 '07 #2
largedimples
4 New Member
I don't see data declaration,wha t is it?

A array of chars?

Savage
The data declaration is char data[256] listed in private section of the class Newstring located in the file Newstring.h. It takes the information from the string title and string lesson listed in the file Newstring.cpp. All file names are bolded.

I remove all parts of length and substring function so you can copy the program and run it.

The output of the program so far is:

The wages of sins is death
The wages of sins is death save me
The gift of god is eternal life
The gift of god is eternal lifes

I need help with adding in substring(Newst ring) and length. I am having problem completing those. The requirement for these are listed in the first submittion of the problem.

Newstring.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include "Newstring. h"
using std::endl;
using std::cout;

void main(void)
{
Newstring title("The wages of sins is death");
Newstring lesson ("The gift of god is eternal life");

title.display() ;
title.concatena te(" save me!");
title.display() ;

lesson.display( );
lesson.concaten ate("s");
lesson.display( );
}


Newstring.h
#ifndef TEST_H
#define TEST_H

class Newstring
{
public:
Newstring (char *); //constructor
void concatenate(cha r *);
void concatenate(cha r);
void display(void);
private:
char data[256];
};
#endif


Newstring1.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include "Test.h"

using std::endl;
using std::cout;

Newstring::News tring(char *str)
{
strcpy_s(data, str);
}

void Newstring::conc atenate (char *str)
{
strcat(data, str);
}

void Newstring::disp lay(void)
{
cout << data <<endl;
length(data);
}
Jun 6 '07 #3
ilikepython
844 Recognized Expert Contributor
The data declaration is char data[256] listed in private section of the class Newstring located in the file Newstring.h. It takes the information from the string title and string lesson listed in the file Newstring.cpp. All file names are bolded.

I remove all parts of length and substring function so you can copy the program and run it.

The output of the program so far is:

The wages of sins is death
The wages of sins is death save me
The gift of god is eternal life
The gift of god is eternal lifes

I need help with adding in substring(Newst ring) and length. I am having problem completing those. The requirement for these are listed in the first submittion of the problem.

Newstring.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include "Newstring. h"
using std::endl;
using std::cout;

void main(void)
{
Newstring title("The wages of sins is death");
Newstring lesson ("The gift of god is eternal life");

title.display() ;
title.concatena te(" save me!");
title.display() ;

lesson.display( );
lesson.concaten ate("s");
lesson.display( );
}


Newstring.h
#ifndef TEST_H
#define TEST_H

class Newstring
{
public:
Newstring (char *); //constructor
void concatenate(cha r *);
void concatenate(cha r);
void display(void);
private:
char data[256];
};
#endif


Newstring1.cpp
#include <iostream>
#include <string>
#include <cstring>
#include <iomanip>
#include "Test.h"

using std::endl;
using std::cout;

Newstring::News tring(char *str)
{
strcpy_s(data, str);
}

void Newstring::conc atenate (char *str)
{
strcat(data, str);
}

void Newstring::disp lay(void)
{
cout << data <<endl;
length(data);
}
For the lenght function try changing the if statement to:
Expand|Select|Wrap|Line Numbers
  1. if (data[i] != '\0')
  2.  
Jun 6 '07 #4
largedimples
4 New Member
For the lenght function try changing the if statement to:
Expand|Select|Wrap|Line Numbers
  1. if (data[i] != '\0')
  2.  
Thanks for the advice but it didn't work. I got the following errors:

1>c:\Newstring. h(15) : error C2365: 'Newstring::len gth' : redefinition; previous definition was 'member function'
1> c:\Newstring.h( 8) : see declaration of 'Newstring::len gth'


1>c:\Newstring. h(15) : error C2365: 'Newstring::len gth' : redefinition; previous definition was 'member function'
1> c:\Newstring.h( 8) : see declaration of 'Newstring::len gth'


1>c:\Newstring1 .cpp(25) : error C3867: 'Newstring::len gth': function call missing argument list; use '&Newstring::le ngth' to create a pointer to member
1>Generating Code...

1>Newstring - 3 error(s), 0 warning(s)
Jun 6 '07 #5
ilikepython
844 Recognized Expert Contributor
Thanks for the advice but it didn't work. I got the following errors:

1>c:\Newstring. h(15) : error C2365: 'Newstring::len gth' : redefinition; previous definition was 'member function'
1> c:\Newstring.h( 8) : see declaration of 'Newstring::len gth'


1>c:\Newstring. h(15) : error C2365: 'Newstring::len gth' : redefinition; previous definition was 'member function'
1> c:\Newstring.h( 8) : see declaration of 'Newstring::len gth'


1>c:\Newstring1 .cpp(25) : error C3867: 'Newstring::len gth': function call missing argument list; use '&Newstring::le ngth' to create a pointer to member
1>Generating Code...

1>Newstring - 3 error(s), 0 warning(s)
You have a function and an integer both named "lenght". Try changing the name of the integer to something else.
Jun 6 '07 #6
largedimples
4 New Member
You have a function and an integer both named "lenght". Try changing the name of the integer to something else.
I tried it--it didn't work
Jun 7 '07 #7
ilikepython
844 Recognized Expert Contributor
I tried it--it didn't work
You got the exact same errors?
Jun 7 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

16
6755
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site... this number is always changing as I have hundreds of thousand of pages of text on my site. Problem: - in my opinion this just not only look weird, but the variable "n" (number)
5
31180
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it will split myString up using the delimiter of 1 space so that
9
8004
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc., etc. The intent is to finish by assigning the list to a string that I would write to disk: recstr = string.join(recd,'')
9
3697
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?
10
8184
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is effectively impossible to forward declare std::string. (Yes I am aware that some libraries have a string_fwd.h header, but this is not portable.) That said, is there any real reason why I can't derive an otherwise empty
2
4784
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
4
34096
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space for storing the XML value. This makes my life a bit easier since I can easilly reallocate space to include the required new space.
29
4324
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return substring before a pattern), AFTER (return substring after a pattern), and BETWEEN (return substring between 2 patterns). My questions are: 1. Can any tell me how I can implement such functionality in C#? 2. Is it possible to add/include function...
4
1764
by: Emilio | last post by:
Question about Shared Sub Connect(server As , message As ) Why is in square brackets? Is it like Shared Sub Connect(server() As String, message() As String)
2
3179
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was a tasty burger"
0
9646
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, 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...
0
9484
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,...
0
10350
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, 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...
0
10157
jinu1996
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...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
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();...
0
5386
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...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2887
bsmnconsultancy
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...

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.