GithubHelp home page GithubHelp logo

vaishnavi-saravanan / 19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aswini-j/19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation

0.0 0.0 0.0 4 KB

C# 100.00%

19ai308-object-oriented-programming-using-csharp-exp-10-file-manipulation's Introduction

19AI308-Object-Oriented-Programming-using-CSharp-Exp-10-File-Manipulation

Develop a C# program to get the values from the user using structure and store it in a file in a specific path using file stream concept

AIM:

To develop a C# program using file streams.

ALGORITHM :

Step 1 :

Define a structure UserData to hold user data fields like name, age, and email.

Step 2 :

Create an array of UserData to store multiple user data entries. Use a loop to prompt the user to input their name, age, and email, and store the input in the array.

Step 3 :

Specify the file path where the user data will be stored.

Step 4 :

Inside the loop, for each user data entry, open the file in append mode using StreamWriter and write the user data to the file.

Step 5 :

Close the file after writing all user data.

Step 6 :

Display a message indicating that the user data has been saved to the file.

PROGRAM :

DEVELOPED BY : VAISHNAVI S
REG NO : 212222230165

using System;

struct student
{
    public string name;

    public int age;

    public int marks;
};

class Program
{
    static void Main(string[] args)
    {
        student[] s  = new student[5];
        for (int i=0; i < 5; i++)
        {
            s[i].name = Console.ReadLine();
            s[i].age = Convert.ToInt32(Console.ReadLine());
            s[i].marks = Convert.ToInt32(Console.ReadLine());
        }
        string path = @"C:\studentInfo.txt";
        using (StreamWriter sw = File.AppendText(path))
        {
            for (int i = 0; i < 5; i++)
            {
                sw.WriteLine(s[i].name + " " + s[i].age + " " + s[i].marks);
            }
        }
        Console.WriteLine(File.ReadAllText(path));
    }
}

OUTPUT :

file

RESULT :

Thus the C# program to get the values from the user using structure and store it in a file in a specific path using file stream concept executed successfully.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.