loading...

Small Ruby and C# script to track names

kironroy profile image Kiron Roy ・2 min read

This small ruby script was made eons ago:

Names tracker Program below:

def prompt(msg) 
  puts "#{msg}"
end

prompt("Enter full names.  Press enter twice to finish the list")

names_arr = []

while true
  user_input = gets.chomp.gsub(/\w+/) do |word| word.capitalize
 end
  break if user_input.empty?
names_arr << user_input
end

names_arr.sort

for index in 0 ... names_arr.size
  prompt("Position of name[#{index}] = #{names_arr[index].inspect}")
end

names_arr_output = "Names in order: " + names_arr.sort.join(", ")
names_arr_amount = "Total number of people: " + names_arr.size.to_s

names_arr_first = "The first name entered: " + names_arr.first
names_arr_last = "The last name entered: " + names_arr.last 

prompt('-' * 30)
prompt('')
prompt(names_arr_output)
prompt('')
prompt(names_arr_amount)
prompt('')
prompt(names_arr_first)
prompt('')
prompt(names_arr_last)
prompt('')

Ruby script sample output:

Enter full names.  Press enter twice to finish the list
 sita
 mita
 gita
 bita
 rita
 anita

Position of name[0] = "Sita"
Position of name[1] = "Mita"
Position of name[2] = "Gita"
Position of name[3] = "Bita"
Position of name[4] = "Rita"
Position of name[5] = "Anita"
------------------------------

Names in order: Anita, Bita, Gita, Mita, Rita, Sita

Total number of people: 6

The first name entered: Sita

The last name entered: Anita

Ruby program on Repl.it

C# Console Application (Partial Code)

using System;
using System.Collections.Generic;
using System.Globalization;

namespace FullNameTracker
{
  class Program
    {
        static void Main(string[] args)
        {
            List<string> firstNamesList = new List<string>();

            string firstNamesInputCaps = StoringTheNames(firstNamesList);

            PrintingTheNamesToConsole(firstNamesList, firstNamesInputCaps);

            EndApplication endApplication = new EndApplication();
            endApplication.EndTheApplication();
        }
   }

}

private static void PrintingTheNamesToConsole(List<string> firstNamesList, string firstNamesInputCaps)

private static string StoringTheNames(List<string> firstNamesList)

C# script sample output:

Original list of names
------------------------------------
Rita
Sita
Mita
Zelda
Anita
Bita
Kelly
------------------------------------

First entry in the list: Rita
------------------------------------

Last entry in the list: Kelly
------------------------------------

List sorted by first name
------------------------------------
Anita
Bita
Kelly
Mita
Rita
Sita
Zelda
------------------------------------

Total names in the list: 7

Press any key to quit application

C# program on Repl.it

Posted on by:

Discussion

markdown guide