Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 106679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:38:05+00:00 2026-05-11T01:38:05+00:00

I have to write a program that read from a file that contains the

  • 0

I have to write a program that read from a file that contains the folowing:

toto, M, 50 fifi, F, 60 soso, F, 70 lolo, M, 60 fifi, F, 60 

And then find the following:

Which mark is most repeated, and how many times is it repeated?

  • average all students
  • average all male
  • average all female

How many are below average mark?

How many more than average mark?

And reverse.

How many students’ names start with T and end with T in a file?

(all results should be placed in an out file)


I’ve done it all with no errors but its not writing on the file can any one tell me why and please I don’t want to use any new methods as (LINQ and other advance stuff).

    using System; using System.Collections.Generic;  using System.Text; using System.IO;  namespace Exam_Ex {     class Program     {         public static int[] ReadFile(string FileName, out string[] Name, out char[] Gender)         {             Name = new string[1];             int[] Mark = new int[1];             Gender = new char[1];             if (File.Exists(FileName))             {                 FileStream Input = new FileStream(FileName, FileMode.Open, FileAccess.Read);                 StreamReader SR = new StreamReader(Input);                 string[] Current;                 int Counter = 0;                 string Str = SR.ReadLine();                 while (Str != null)                 {                     Current = Str.Split(',');                     Name[Counter] = Current[0];                     Mark[Counter] = int.Parse(Current[2]);                     Gender[Counter] = char.Parse(Current[1].ToUpper());                     Counter++;                     Array.Resize(ref Name, Counter + 1);                     Array.Resize(ref Mark, Counter + 1);                     Array.Resize(ref Gender, Counter + 1);                     Str = SR.ReadLine();                 }             }             return Mark;         }          public static int MostFreq(int[] M, out int Frequency)         {             int Counter = 0;             int Frequent = 0;             Frequency = 0;             for (int i = 0; i < M.Length; i++)             {                 Counter = 0;                 for (int j = 0; j < M.Length; j++)                     if (M[i] == M[j])                         Counter++;                 if (Counter > Frequency)                 {                     Frequency = Counter;                     Frequent = M[i];                 }             }             return Frequent;         }          public static int Avg(int[] M)         {             int total = 0;             for (int i = 0; i < M.Length; i++)                 total += M[i];             return total / M.Length;         }          public static int AvgCond(char[] G, int[] M, char S)         {             int total = 0;             int counter = 0;             for (int i = 0; i < G.Length; i++)                 if (G[i] == S)                 {                     total += M[i];                     counter++;                 }             return total / counter;         }          public static int BelowAvg(int[] M, out int AboveAvg)         {             int Bcounter = 0;             AboveAvg = 0;             for (int i = 0; i < M.Length; i++)             {                 if (M[i] < Avg(M))                     Bcounter++;                 else                     AboveAvg++;             }             return Bcounter;         }          public static int CheckNames(string[] Name, char C)         {             C = char.Parse(C.ToString().ToLower());             int counter = 0;             string Str;             for (int i = 0; i < Name.Length - 1; i++)             {                 Str = Name[i].ToLower();                 if (Str[0] == C || Str[Str.Length - 1] == C)                     counter++;             }             return counter;         }          public static void WriteFile(string FileName, string[] Output)         {             FileStream FS = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.Write);             StreamWriter SW = new StreamWriter(FS);             for (int i = 0; i < Output.Length; i++)                 SW.WriteLine(Output[i]);         }          static void Main(string[] args)         {             int[] Mark;             char[] Gender;             string[] Name;             string[] Output = new string[8];             int Frequent, Frequency, AvgAll, MaleAvg, FemaleAvg, BelowAverage, AboveAverage, NamesCheck;             Mark = ReadFile("c:\\IUST1.txt", out Name, out Gender);             Frequent = MostFreq(Mark, out Frequency);             AvgAll = Avg(Mark);             MaleAvg = AvgCond(Gender, Mark, 'M');             FemaleAvg = AvgCond(Gender, Mark, 'F');             BelowAverage = BelowAvg(Mark, out AboveAverage);             NamesCheck = CheckNames(Name, 'T');             Output[0] = "Frequent Mark = " + Frequent.ToString();             Output[1] = "Frequency = " + Frequency.ToString();             Output[2] = "Average Of All = " + AvgAll.ToString();             Output[3] = "Average Of Males = " + MaleAvg.ToString();             Output[4] = "Average Of Females = " + FemaleAvg.ToString();             Output[5] = "Below Average = " + BelowAverage.ToString();             Output[6] = "Above Average = " + AboveAverage.ToString();             Output[7] = "Names With \"T\" = " + NamesCheck.ToString();             WriteFile("d:\\output.txt", Output);         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T01:38:05+00:00Added an answer on May 11, 2026 at 1:38 am

    I haven’t test it. But you should call SW.close() after finished writing stuffs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have a queuing mechanism in C on Unix. It accepts XML transactions. Some
I'm currently trying to create a kernel module that will produce data based on
I am trying to create a file in the /tmp directory (working on a
I have a project that I thought was going to be relatively easy, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.