473,320 Members | 2,071 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,320 software developers and data experts.

Create String, String Concatenation & Newline Characters

I am very new to C#. I need help with creating the string, concatenating the string and displaying the information on separate lines.

Here is what I am doing:

1. Write this Application in C#
2. It is a Console Application.
3. Use “MileStones” as a Namespace.
4. You shall have two files:
a. TestApp.cs
b. Person.cs
5. Use of accessors/ modifiers are mandatory.

6. TestApp class will be a Console Application with:
a. A person object that makes reference to Person.cs class
b. Will ask the user to enter “person” information

Here is the class diagram for Person class:

Person
- personID: ulong
- surname: string
- givenName: string
- middleInitial: string
- streetAddress: string
- city: string
- state: string
- postcode: string
- countryName: string
- eMailAddress: string

Constructors and Method:

+ Person()
+ Person (int32 id)
+ PersonInfo()

7. First: the application will ask the user to enter “Person” information.

The output should look like:

---- Reading Person’s Info:
Enter the person ID: 123
Enter Lastname: Fraticelli
Enter Firstname: Meli
Enter Middle Initial: S
Enter Street Address: 233 The Street
Enter City: SmallTown
Enter State: TX
Enter Post code: 76118
Enter Country: USA
Enter Email Address: efraticelli@csc.com

8. Second: Console Application will display “person” information just entered.

The output should look like this:

---- Displaying Person’s info by calling PersonInfo
-------------------------------------------
Meli S Fraticelli
233 The Street
SmallTown, TX 76118
USA
Email: efraticelli@csc.com
------------------------------------
--Bye

I would appreciate any assistance you could give me.

- Ldphill
Nov 13 '07 #1
7 1735
nateraaaa
663 Expert 512MB
We do not answer homework questions here. Please try writing code on your own then if you get stuck post the code you are having problems with and we will help you fix the problem.

Nathan
Nov 13 '07 #2
r035198x
13,262 8TB
I am very new to C#. I need help with creating the string, concatenating the string and displaying the information on separate lines.

Here is what I am doing:

1. Write this Application in C#
2. It is a Console Application.
3. Use “MileStones” as a Namespace.
4. You shall have two files:
a. TestApp.cs
b. Person.cs
5. Use of accessors/ modifiers are mandatory.

6. TestApp class will be a Console Application with:
a. A person object that makes reference to Person.cs class
b. Will ask the user to enter “person” information

Here is the class diagram for Person class:

Person
- personID: ulong
- surname: string
- givenName: string
- middleInitial: string
- streetAddress: string
- city: string
- state: string
- postcode: string
- countryName: string
- eMailAddress: string

Constructors and Method:

+ Person()
+ Person (int32 id)
+ PersonInfo()

7. First: the application will ask the user to enter “Person” information.

The output should look like:

---- Reading Person’s Info:
Enter the person ID: 123
Enter Lastname: Fraticelli
Enter Firstname: Meli
Enter Middle Initial: S
Enter Street Address: 233 The Street
Enter City: SmallTown
Enter State: TX
Enter Post code: 76118
Enter Country: USA
Enter Email Address: efraticelli@csc.com

8. Second: Console Application will display “person” information just entered.

The output should look like this:

---- Displaying Person’s info by calling PersonInfo
-------------------------------------------
Meli S Fraticelli
233 The Street
SmallTown, TX 76118
USA
Email: efraticelli@csc.com
------------------------------------
--Bye

I would appreciate any assistance you could give me.

- Ldphill
and what have you done so far? Start with the Person class and post if you get stuck writing the code.
Nov 13 '07 #3
Here is what I have done so far to Person.cs:

using System;
using System.Collections.Generic;
using System.Text;

namespace MileStones
{
class Person
{
private ulong mPersonID = 0;
private string mSurname = string.Empty;
private string mGivenName = string.Empty;
private string mMiddleInitial = string.Empty;
private string mStreetAddress = string.Empty;
private string mCity = string.Empty;
private string mState = string.Empty;
private string mPostcode = string.Empty;
private string mCountryName = string.Empty;
private string mEmailAddress = string.Empty;

public ulong PersonID
{
get
{
return this.mPersonID;
}
set
{
mPersonID=value;
}
}
public string Surname
{
get
{
return this.mSurname;
}
set
{
mSurname = null;
}
}

public string GivenName
{
get
{
return this.mGivenName;
}
set
{
mGivenName = null;
}
}

public string MiddleInitial
{
get
{
return this.mMiddleInitial;
}
set
{
mMiddleInitial = null;
}
}

public string StreetAddress
{
get
{
return this.mStreetAddress;
}
set
{
mStreetAddress = null;
}
}

public string City
{
get
{
return this.mCity;
}
set
{
mCity = null;
}
}

public string State
{
get
{
return this.mState;
}
set
{
mState = null;
}
}

public string Postcode
{
get
{
return this.mPostcode;
}
set
{
mPostcode = null;
}
}

public string CountryName
{
get
{
return this.mCountryName;
}
set
{
mCountryName = null;
}
}

public string EmailAddress
{
get
{
return this.mEmailAddress;
}
set
{
mEmailAddress = null;
}
}
public Person()
{

}

public Person(Int32 PersonID)
{

}

public string PersonInfo();
string so = "Meli S. Fraticelli";
string s1 = s0 + "\n 233 The Street ";
string s2 = s0 + s1 + "\n SmallTown, TX 76118";
string s3 = s0 + s1 + s2 + "\n




}

}
Nov 13 '07 #4
Plater
7,872 Expert 4TB
For windows, try using "\r\n" for newline characters.

Also, some of your properties had this:
Expand|Select|Wrap|Line Numbers
  1. public string CountryName
  2. {
  3.    get
  4.    {
  5.       return this.mCountryName;
  6.    }
  7.    set
  8.    {
  9.       mCountryName = null;
  10.    }
  11. }
  12.  
Why do you set it to null and not this.mCountryName=value; ?
Nov 13 '07 #5
r035198x
13,262 8TB
For windows, try using "\r\n" for newline characters.

Also, some of your properties had this:
Expand|Select|Wrap|Line Numbers
  1. public string CountryName
  2. {
  3.    get
  4.    {
  5.       return this.mCountryName;
  6.    }
  7.    set
  8.    {
  9.       mCountryName = null;
  10.    }
  11. }
  12.  
Why do you set it to null and not this.mCountryName=value; ?
Your PersonInfo method does not look right.
Whenever you write code, make it a point to try it on the compiler and pay attention to the error messages that you get.

You are also missing the default constructor and need to make your 1 -arg constructor do something about the argument that it received.
Nov 13 '07 #6
I have corrected some of my code since my last post. This is what I have now.
In Person.cs, I am not sure what to put in my second constructor [Person (int32 id)]. In TestApp.cs, I am not sure of what to equal Console.ReadLine();.
I know it has to be something from Person object created. I have to create Person object and place data in there. I WOULD APPRECIATE ANY ASSISTANCE YOU COULD GIVE ME.

- Ldphill


Person.CS

using System;
using System.Collections.Generic;
using System.Text;

namespace MileStones
{
class Person
{
private ulong mPersonID = 1;
private string mSurname = string.Empty;
private string mGivenName = string.Empty;
private string mMiddleInitial = string.Empty;
private string mStreetAddress = string.Empty;
private string mCity = string.Empty;
private string mState = string.Empty;
private string mPostcode = string.Empty;
private string mCountryName = string.Empty;
private string mEmailAddress = string.Empty;

public ulong PersonID
{
get
{
return this.mPersonID;
}
set
{
this.mPersonID=value;
}
}
public string Surname
{
get
{
return this.mSurname;
}
set
{
this.mSurname = value;
}
}

public string GivenName
{
get
{
return this.mGivenName;
}
set
{
this.mGivenName = value;
}
}

public string MiddleInitial
{
get
{
return this.mMiddleInitial;
}
set
{
this.mMiddleInitial = value;
}
}

public string StreetAddress
{
get
{
return this.mStreetAddress;
}
set
{
this.mStreetAddress = value;
}
}

public string City
{
get
{
return this.mCity;
}
set
{
this.mCity = value;
}
}

public string State
{
get
{
return this.mState;
}
set
{
this.mState = value;
}
}

public string Postcode
{
get
{
return this.mPostcode;
}
set
{
this.mPostcode = value;
}
}

public string CountryName
{
get
{
return this.mCountryName;
}
set
{
this.mCountryName = value;
}
}

public string EmailAddress
{
get
{
return this.mEmailAddress;
}
set
{
this.mEmailAddress = value;
}
}
public Person()
{

}

public Person(Int32 PersonID)
{

}

public string PersonInfo()
{
string s0 = mGivenName + " " + mMiddleInitial + " " + mSurname;
s0 += "\n" + mStreetAddress;
s0 += "\n" + mCity + "," + " " + mState + " " + mPostcode;
s0 += "\n" + mCountryName;
s0 += "\n" + mEmailAddress;

return s0;
}

}

}


TestApp.CS

using System;
using System.Collections.Generic;
using System.Text;

namespace MileStones
{
class TestApp
{
static void Main(string[] args)
{
Person obj = new Person();

Console.WriteLine("Enter Person ID:");
Console.ReadLine();
Console.WriteLine("Enter Lastname:");
Console.ReadLine();
Console.WriteLine("Enter Firstname:");
Console.ReadLine();
Console.WriteLine("Enter Middle Initial:");
Console.ReadLine();
Console.WriteLine("Enter Street Address:");
Console.ReadLine();
Console.WriteLine("Enter City:");
Console.ReadLine();
Console.WriteLine("Enter State:");
Console.ReadLine();
Console.WriteLine("Enter Postcode:");
Console.ReadLine();
Console.WriteLine("Enter Country:");
Console.ReadLine();
Console.WriteLine("Enter Email Address:");
Console.ReadLine();

}

}

}
Nov 14 '07 #7
r035198x
13,262 8TB
Just looking at the Person class first (which you should be doing) ...
You are over-using the "this" word in your properties.
return PropertyName will do just fine.
Your no argument constructor should intialize your properties to appropriate default values.
Your 1 arg constructor should set the id of that Person object to be the id that was supplied to it and intialize the rest of the fields to appropriate values.
You should avoid adding strings using + if you need to add lots of them together. StringBuilder is the right tool for the job (faster).
Nov 14 '07 #8

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

Similar topics

4
by: Jeff Rodriguez | last post by:
Main just loops over this while it's not null. The segfault occurs at this line: *line = (char)ch; Also, please don't just fix the code. I would like to know why exactly this isn't working so I...
3
by: Mythran | last post by:
Out of curiosity, only, which is recommended for SHORT concatenation...or concatenating two or three strings that are relatively small in size? Dim a As String = "bah" Dim b As String = "bah2"...
33
by: genc_ymeri | last post by:
Hi over there, Propably this subject is discussed over and over several times. I did google it too but I was a little bit surprised what I read on internet when it comes 'when to use what'. Most...
8
by: Mike S | last post by:
Hi all, I noticed a very slight logic error in the solution to K&R Exercise 1-22 on the the CLC-Wiki, located at http://www.clc-wiki.net/wiki/KR2_Exercise_1-22 The exercise reads as...
5
by: Jayson Davis | last post by:
Say I have a string read from a configuration file. searchfor <tab> Needle\n\n Where I want to search for the word "Needle" with two linefeeds. Now when I read it from the file, it hasn't...
9
by: will | last post by:
I have an XML input that includes things like: <foo>line of text another line of text yet another</foo> And I want the entities PRESERVED (not translated) on the result, so: <bar>line of...
18
by: Andrew Backer | last post by:
Is it possible to embed a newline constant in a string in the same way as c#? I really don't want to do something like this: ++ String.Format("Line 1 : {0} " & vbcrlf & " Line 2 : {1}", o, t)...
14
by: arnuld | last post by:
i have slightly modified the programme from section 1.5.1 which takes the input frm keyboard and then prints that to the terminal. it just does not run and i am unable to understand the error...
17
by: Andrew C. | last post by:
I'm trying to complete excercise 1-23 in the K&R book, which calls for a program to wrap input lines at a given column, making sure to handle lines that wrap twice or don't contain whitespace. This...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.