Question

File l/O Create a Person class (firstName, lastName, phoneNumber, gender (Use radioButtons for gender in the GUI) ) Create a

answer in c# console application.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output:

Form1 First Name nayantharar35546346female nayan tharan Last Name Phone Number 35546346 O FeMale Male Add Display Read X

Form.cs:

using System;
using System.Collections.Generic;
using System.Linq;

using System.Windows.Forms;
using System.IO;

namespace FileOperationForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

List<Person> list = new List<Person>();
private void button1_Click(object sender, EventArgs e)
{
Person obj = new Person();
obj.firstname = textBox1.Text;
obj.lastName = textBox2.Text;
obj.phoneNumber = textBox3.Text;
if(radioButton1.Checked==true)
{
obj.male = true;
}
else
{
obj.female = true;
}

list.Add(obj);


using (StreamWriter writer = new StreamWriter("..\\..\\TextFile1.txt", true))
{
writer.WriteLine(obj.firstname + obj.lastName+obj.phoneNumber);
if(obj.male==true)
{
writer.WriteLine("Male");
}
else
{
writer.WriteLine("FeMale");
}
}

}

private void button2_Click(object sender, EventArgs e)
{
  
for(int i=0;i<list.Count;i++)
{
richTextBox1.Text += list[i].firstname + list[i].lastName + list[i].phoneNumber;
if(list[i].male==true)
{
richTextBox1.Text += "male";
}
else
{
richTextBox1.Text += "female";
}

richTextBox1.Text += Environment.NewLine;
}

}

private void button3_Click(object sender, EventArgs e)
{
using (StreamReader reader = new StreamReader("..\\..\\TextFile1.txt"))
{
while (true)
{
string line = reader.ReadLine();
if (line == null)
{
break;
}

}
}
}
}

class Person
{
public string firstname;
public string lastName;
public string phoneNumber;
public bool female;
public bool male;
}
}

Designer code:

namespace FileOperationForm
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(40, 46);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(57, 13);
this.label1.TabIndex = 0;
this.label1.Text = "First Name";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(40, 95);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(58, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Last Name";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(40, 152);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(78, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Phone Number";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(127, 46);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 3;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(127, 92);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 4;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(139, 152);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(100, 20);
this.textBox3.TabIndex = 5;
//
// radioButton1
//
this.radioButton1.AutoSize = true;
this.radioButton1.Location = new System.Drawing.Point(92, 223);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(48, 17);
this.radioButton1.TabIndex = 6;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "Male";
this.radioButton1.UseVisualStyleBackColor = true;
//
// radioButton2
//
this.radioButton2.AutoSize = true;
this.radioButton2.Location = new System.Drawing.Point(297, 223);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(60, 17);
this.radioButton2.TabIndex = 7;
this.radioButton2.TabStop = true;
this.radioButton2.Text = "FeMale";
this.radioButton2.UseVisualStyleBackColor = true;
//
// button1
//
this.button1.Location = new System.Drawing.Point(43, 314);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 8;
this.button1.Text = "Add ";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(216, 314);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 9;
this.button2.Text = "Display";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(395, 314);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 10;
this.button3.Text = "Read";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(315, 46);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(192, 151);
this.richTextBox1.TabIndex = 11;
this.richTextBox1.Text = "";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(572, 449);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.radioButton2);
this.Controls.Add(this.radioButton1);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.

Add a comment
Know the answer?
Add Answer to:
answer in c# console application. File l/O Create a Person class (firstName, lastName, phoneNumber, gender (Use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • ****THIS IS A 2 PART QUESTION! I ONLY NEED THE ANSWER TO PART 2 ON HOW...

    ****THIS IS A 2 PART QUESTION! I ONLY NEED THE ANSWER TO PART 2 ON HOW TO SEND THE DATA SERIALIZED**** Write a c# program that stores student grades in a text file and read grades from a text file.  The program has the following GUI: There are four buttons: Create File, Save Case, Close File and Load File.  Initially, only the Create File and Load File buttons are enabled.  If the user clicks the Create File button, a Save File Dialog window...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

  • In this assignment, you will create an application that holds a list of contact information. You ...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. MUST BE IN PYTHON FORMAT Create the folllowing objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • In this assignment, you will create an application that holds a list of contact information. You...

    In this assignment, you will create an application that holds a list of contact information. You will be able to prompt the user for a new contact, which is added to the list. You can print the contact list at any time. You will also be able to save the contact list. Must Be In Python Format Create the following objects: ContactsItem - attributes hold the values for the contact, including FirstName - 20 characters LastName - 20 characters Address...

  • I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the...

    I. User Interface Create a JavaFX application with a graphical user interface (GUI) based on the attached “GUI Mock-Up”. Write code to display each of the following screens in the GUI: A. A main screen, showing the following controls: • buttons for “Add”, “Modify”, “Delete”, “Search” for parts and products, and “Exit” • lists for parts and products • text boxes for searching for parts and products • title labels for parts, products, and the application title B. An add...

  • GUI programming

    Please use netBeans Exercise 4:A librarian needs to keep track of the books he has in his Library.1. Create a class Book that has the following attributes: ISBN, Title, Author, Subject, and Price. Choose anappropriate type for each attribute.2. Add a static member BookCount to the class Book and initialize it to zero.3. Add a default constructor for the class Book. Increment the BookCount static member variable and an initialization constructor for the class Book. Increment the BookCount in all constructors.4....

  • write a Java console application that Create a text file called Data.txt. Within the file, use...

    write a Java console application that Create a text file called Data.txt. Within the file, use the first row for the name and data title, and use the second row for column headers. Within the columns, insure that the first column is a label column and other columns contain numeric data. In your application, read file Data.txt into parallel arrays, one for each column in the file. Create method printArrays to print the header row(s) and the (unsorted) data in...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT