Introduction to Storage

Introduction to Computer Languages

A computer programming language, also called a computer language, or a programming language, is used to give instructions to a computer to perform a specific assignment. Like a spoken language, a computer language has meaning words, syntaxes, grammar, formulas, and rules that must be followed to construct meaningful sentences. Just like there are many languages, there are also various types of computer languages. A significant characteristic of computer languages, as opposed to human languages, is that they are categorized by roles or purposes.

Practical LearningPractical Learning: Introducing Values

  1. Start Microsoft Visual Studio
  2. On the main menu, click Project -> New -> Project...
  3. In the middle frame, click Console App (.NET Framework)
  4. Change the name to PayrollPreparation4
  5. Press Enter
  6. In the Solution Explorer, right-click PayrollPreparation4 and click Rename
  7. Type PayrollPreparation to get AccountCreation.cs, and press Enter
  8. Read the text on the message box and click Yes
  9. Change the document as follows:
    using static System.Console;
    
    namespace PayrollPreparation4
    {
        public class AccountCreation
        {
            public static void Main(string[] args)
            {
                string strUsername = string.Empty;
    
                WriteLine("Account Creation");
                WriteLine("---------------------------------");
                WriteLine("Provide the following information");
                Write("First Name:       ");
                string strFirstName = ReadLine();
                Write("Middle Name:      ");
                string strMiddleName = ReadLine();
                Write("Last Name:        ");
                string strLastName = ReadLine();
                WriteLine("---------------------------------");
                Write("Password:         ");
                string strNewPassword = ReadLine();
                Write("Confirm Password: ");
                string strConfirmPassword = ReadLine();
    
                Clear();
    
                WriteLine("Account Summary");
                WriteLine("----------------------------");
                WriteLine("First Name:      " + strFirstName);
                WriteLine("Middle Name:     " + strMiddleName);
                WriteLine("Last Name:       " + strLastName);
                WriteLine("-------------------------------------------");
    
                if (strMiddleName.Length == 0)
                    strUsername = string.Concat(strFirstName.Substring(0, 1), strLastName).ToLower();
                else
                    strUsername = string.Concat(strFirstName.Substring(0, 1), strMiddleName.Substring(0, 1), strLastName).ToLower();
                WriteLine("Username:        " + strUsername);
    
                if (strNewPassword.Equals(strConfirmPassword))
                {
                    WriteLine("Password:        " + strNewPassword);
                }
                else
                {
                    WriteLine("The passwords you entered don't match.");
                }
                WriteLine("===========================================");
            }
        }
    }
  10. To execute, on the main menu, click Debug -> Start Without Debugging:
    Account Creation
    ---------------------------------
    Provide the following information
    First Name:
  11. Type some values as follows:
    Account Creation
    ---------------------------------
    Provide the following information
    First Name:       Roberto
    Middle Name:      Carlos
    Last Name:        Solorio
    ---------------------------------
    Password:         Password1
    Confirm Password: Password1
  12. Press Enter:
    Account Summary
    ----------------------------
    First Name:      Roberto
    Middle Name:     Carlos
    Last Name:       Solorio
    -------------------------------------------
    Username:        rcsolorio
    Password:        Password1
    ===========================================
    Press any key to continue . . .
  13. Press Enter to close the window and return to your programming environment

Introduction to Electronic Devices

A computer is an electronic device that is used to solve one specific problem or to perform an assignment. For example, a fitness machine allows a person to get in shape. A digital camera is used to take pictures. A cell phone is used to make phone calls. An ultrasound machine is a health care machine used to produce images from inside a human body. A music synthesizer can be used to create music:

Computer

Music Device

Cell Phone

Music Device

Music Device

An electronic device can also be used to solve general types of problems. For example, a personal computer (PC) can be used to perform calculations, word processing, or to store a database, etc.

Tto perform its assignment(s), a computer must receive values. This can be done by a person typing from a keyboard (cell phone, health care machine, PC, etc). Another machine would allow a user to only select from a preset number of keys (fitness machine, airplane, car, digital camera, microwave oven, refrigerator, etc). A person can also be asked to click something using the mouse. A person can also be asked to press some objects on a touch screen. In some cases, the values can come electronically (internally) from other sources (car, projector, etc). A computer can also get its values from a  combination of sources:

Information

To manage these different connections, a computer uses a flat object called a motherboard. Many parts are connected to this board. For example, there is a small machine whose main job is to perform calculations; it is called a processor, and it is connected to the motherboard. Then external objects are connected to the parts connected to the motherboard:

Information

The values a computer receives must be stored somewhere, called memory (like human memory). The computer uses two categories of storage (memory): temporary and permanent. We will come back to permanent storage in a later lesson (not because it is difficult but because we don't need it for now). The computer's temporary memory is used to hold information for a while and then lose it if that information is not needed anymore. For example, it can hold some values while the computer is turned on. If the computer gets turned off, the values stored in the temporary memory are lost. This is not an anomaly: that's the way it is designed (it would be catastrophic otherwise; try to imagine a computer that would keep everything; it would be filled in a short time and blow up :)).

The memory area where the computer temporarily stores some values is called random access memory or RAM:

Random Access Memory

Let's illustrate memory as a small cake pan made of boxes or holes that can contain something:

Variable Representation

We must mention, and keep in mind, that memory is larger than that and is made of millions of these hole-like objects.

As a programmer, your most regular job will consist of asking the compiler to temporarily store one or more values in the RAM. Without considering its small physical size, you should know that the RAM is huge, and you are (or your program is) not the only one using it. In fact, your program will not be the only one that uses the computer. For example, when the computer starts, it launches a program named an operating system (OS). Other programs (and utilities) also come to occupy the RAM.

To be able to manage the frequent requests of memory of your application, when you start a program, the compiler reserves a certain area of memory:

Reserved Memory

Because many programs use the RAM, if/when you want to store a value in it, you must provide some pieces of information. You must indicate the amount or memory you need and you must create a name that would be used to refer to that area of memory. The combination of these two pieces of information is called a variable.

Values on the Console

The applications of a C# language display their results in a dark DOS window. Here is an example:

To display a value in this window, you can pass it to the System.Console.Write() or the System.Console.WriteLine() method.

Numeric Representations

Introduction

A computer program is a series of instructions that tell the computer what to do, when to do something, and how to do it. To understand the instructions, the computer uses its own language. And actually, they don't. Instead, a computer language such as C#, that uses English, submits its instructions to an intermediary program named an assembler. The assembler transforms the previous instructions into a shorter version that uses new words but that are still in English. Using this new version, the assembler transforms the instructions in an even more simplified version (in reality, there is nothing simple with this process) that the computer can understand.

The simplified language the computer understands uses a combination of 1s and 0s. This means that the assembler must bring your C# instructions to 1s and 0s. The combinations or sequences of 1s and 0s indicate what needs to be done.

Numeric Systems

We are familiar with the system that uses 10 digits as 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. A combination of these 10 digits can produce any number we want. Because this system uses 10 digits. It is named the decimal system.

As mentioned already, the language of the computer is made of combinations of two values: 1 and 0. This is called the binary system (because it is based on two values only). Examples of numbers in the binary system, or binary numbers, are 1, 10, 1001, or 1010110111. When you submit a value to a computer, the value must be changed into a compbination of 1s and 0s.

Hexadecimal Numbers

One way to represent a large number uses the 10 digits of the decimal system and uses the first 6 letters of the English alphabet: A, B, C, E, D, and F or a, b, c, d, e, and f. This means that this system uses a combination of 16 characters to create any number. For this reason, it is called the hexadecimal system. To differenciate a hexadecimal number from a word, the number must start with 0x. Examples are 0x2, or 0xED8, or 0x962AAED3.

Signed and Unsigned

One of the characteristics of a number is to indicate whether it is lower than 0, equal to 0, or higher than 0. A number that is lower than 0 is said to be negative. Such a number must be preceded by -. If a number is higher than 0, it is said to be positive. Such a number can be preceded by + or no sign. The ability for a number to hold a sign makes it possible to say that such a number is signed. It is important to know that, when a number is said to be signed, that number can be negative or positive.

Any number that uses neither - or + is said to be positive and, because it doesn't use a sign, it is said to be unsigned. Normally, the 0 number doesn't use a sign.

A Variable

A variable is an area of memory where you store a value. To it, you must declare a variable, which is done by specifying a data type and a name using the following formula:

data-type variable-name;

You can also use the object or the dynamic keywords for the type. If you want to specify the initial value of the variable, assign the value when declaring the variable. In this case, besides a normal data type, you can also use the var keyword. The formulas tl use are:

data-type variable-name = desired-value;
var data-type variable-name = desired-value;
object data-type variable-name = desired-value;
dynamic data-type variable-name = desired-value;

The Nullity of a Variable

When declaring a variable, if you don't have a value for it, you can indicate that it is null. To do this, if the variable uses a primitive type, type a question mark between the data type and the name of the variable, then assign null to it. This would be done as follows:

data-type? variable1-name = null;
	
data-type? variable2-name;
	
variable2-name = null;

A Bit of Memory

Introduction

We mentioned that, to store a value in the computer memory, you must indicate how much memory you will need and you must give it a name. The amount of memory you need is referred to as a data type. As you can imagine, different values require different amount of memory. We also mentioned that the computer considers a value as a combination of 1s and 0s. The area of memory that holds a single piece of 1 or 0 is called a bit.

Consider a bit like a small object (like a cup of a cup cake) that can be full or can be empty:

Variable Representation

When it is empty, a bit holds a value or 0. When it is full, it holds a value of 1:

Variable Representation

Different combinations of empty (0) and full (1) objects produce the necessary values.

A Combination of Four Bits

You you cannot programmatically store a value in a bit. That is, you cannot ask the compiler to store the value 1 in a certain bit. This is because even the simplest value in C# needs more than one bit to store itself. Still, the minimum combination of bits you can be concerned with is four (in some languages, or in some implementations of the Assembly language, a combination of four bits is called a nibble).

By creating different combinations of empty (0) and full (1) objects grouped in four, you can get 16 combinations:

Combinations of Four Bits Combinations of Four Bits
Combinations of Four Bits Combinations of Four Bits

In a combination of four bits, the bits are counted as 0, 1, 2, and 3. The bit on the most right side is Bit 0 and it is called the low order bit (or LOBIT):

Four Bits

The last bit, the bit on the most left side, is Bit 3 and it is called the high order bit (or HIBIT).

If you represent the four-combination bits in binary formats, you get 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111, which produces 16 combinations. In decimal format, these combinations produce 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, and 15. In hexadecimal format, these combinations produce 0x0 (0x0000), 0x1 (or 0x0001), 0x2 (or 0x0002), 0x3 (or 0x0003), 0x4 (or 0x0004), 0x5 (0x0005), 0x6 (0x0006), 0x7 (or 0x0007), 0x8 (or 0x0008), 0x9 (or 0x0009), 0xA (or 0xa), 0xB (or 0xb), 0xC (or 0xc), 0xD (or 0xd), 0xE (or 0xe), and 0xF (or 0xF).

As a result, we get a table as follows:

Decimal Binary Hexadecimal
0 0000 0x0
1 0001 0x1
2 0010 0x2
3 0011 0x3
4 0100 0x4
5 0101 0x5
6 0110 0x6
7 0111 0x7
8 1000 0x8
9 1001 0x9
10 1010 0xA
11 1011 0xB
12 1100 0xC
13 1101 0xD
14 1110 0xE
15 1111 0xF

Table of Numeric Conversions

The minimum and maximum values in a combination of four bits are:

Decimal Hexadecimal Binary
Minimum 0 0x0 0000
Maximum 15 0xf 1111

You will never be concerned with combinations of four bits because you cannot store anything in it (these combinations are too small). We presented them here for two reasons. First, you should be aware of such a thing as a combination of four bits so you will know where the number 16 comes from when you see it mentioned in different places. Second, it allowed us the introduce the byte.

A Byte: A Combination of 8 Bits

A byte is a combination of eight adjacent bits. The first bit, located on the most right side, is Bit 0. The last bit, on the most left side, is Bit 7:

Byte Representation

Bit 0 is called the least significant bit. It is also valled the low order bit or LOBIT. Bit 7 is called the most significant bit. It is also called the high order bit or HIBIT.

If you create different combinations of empty (0) and full (1) objects grouped in eight, in binary formats, you get 00000000, 00000001, 00000010, 00000011, 00000100, 00000101, 00000110, 00000111, 00001000, 00001001, 00001010, 00001011, 00001100, 00001101, 00001110, 00001111, etc, up to 11111111. When a large number is represented in binary format, it can be difficult to read. An alternative is to create groups of four bits so that instead of writing 01001011, you would write 0100 1011.

To evaluate the number of combinations in decimal format, you use the number 2 that represents decimal, you elevate it to the power of the position of the bit (0, 1, 2, 3, 4, 5, 6, or 7), and you add the number. This can be done as follows:

27 + 26 + 25 + 24 + 23 + 22 + 21 + 20
= 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 255

Therefore, we 255 possible combinations of eight bits. The combinations can also be represented in hexadecimal format as 0x1, 0x2, ..., 0xA, 0xA1, ..., 0xC8, ..., up to 0xFFFF

In the three numeric systems, we get:

Decimal Hexadecimal Binary
Minimum 0 0x0 0000
Maximum 255 0xff 1111 1111

The minimum storage area offered by the (Intel) computer is the byte. As you know already, a byte is a group of 8 consecutive bits.

Characters

Introduction

The amount of memory space offered by a byte can be used to store just a single symbol, also called a character. Characters have been organized by the American Standard Code for Information Exchange, ASCII, in a set list. But, ASCII uses only 128 decimal numbers (based on a 7-bit format) to represent symbols counted from 0 to 127. To compensate for the remaining 1 bit, IBM used it to organize special characters, foreign language characters, mathematical symbols, small graphics, etc. Each one of these characters has a decimal, a hexadecimal, and a binary equivalents.

Each one of the characters you see on your keyboard is represented as a numeric value, but whether it appears as a number, a letter, or a symbol, each one of these is considered a character. To let you display a character on the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a char argument. Their syntaxes are:

public static void Write(char value);
public static void WriteLine(char value);

If you are passing a constant character, it must be include between single-quotes. Here is an example:

using static System.Console;

class Exercise
{
    static void Main()
    {
        WriteLine('n');
    }
}

A Character Variable

To declare a variable that can store a symbol, use the char data type. If you want to initialize the variable when declaring it, you can use the char data type, the object type, the var, or the dynamickeywords. Here is an example:

class Exercise
{
    static void Main()
    {
        var gender = 'F';

        System.Console.Write("Student Gender: ");
        System.Console.WriteLine(gender);
    }
}

Reading a Character

As you may know already, each letter of the alphabet is represented on the keyboard by a key. Other symbols, readable (such as #, @, or $) or not (such as Shift, Ctrl, or Enter) are also represented. To let you get the letter or the action that those keys represent, the Console class is equipped with a method named ReadKey that is overloaded with two versions. One of the versions uses the following syntax:

public static ConsoleKeyInfo ReadKey();

This method takes no argument and produces a value of type ConsoleKeyInfo. To get the value returned by this method, you can declare a ConsoleKeyInfo variable and assign it to the calling of this method.

If the user presses a key for a letter or a readable symbol (such as #, !, /, or %), to recognize the key that was pressed, the ConsoleKeyInfo class is equipped with a member named KeyChar. Here is an example of getting the letter:

using System;

public class Exercise
{
    static int Main()
    {
        ConsoleKeyInfo cki = new ConsoleKeyInfo();

        Console.Write("Press a key: ");
        cki = System.Console.ReadKey();
        Console.WriteLine();

        Console.Write("You pressed: ");
        Console.WriteLine(cki.KeyChar);

        Console.ReadKey();
        return 0;
    }
}

If the key that the user pressed is not a readable symbol such as the Space Bar, a Ctrl key, or Enter, to recognize it, the ConsoleKeyInfo class is equipped with a member named Key. Here is an example of using it:

using System;

public class Exercise
{
    static int Main()
    {
        ConsoleKeyInfo cki = new ConsoleKeyInfo();

        Console.Write("Press a key: ");
        cki = System.Console.ReadKey();
        Console.WriteLine();

        Console.Write("You pressed: ");
        Console.WriteLine(cki.Key);

        Console.ReadKey();
        return 0;
    }
}

When it finishes reading its key, the Console.ReadKey() method stops and lets you decide what to do. If you want it to display the result, the Console class provides another version of the ReadKey() method. Its syntax is:

public static ConsoleKeyInfo ReadKey(bool intercept);

The Boolean argument specifies whether you want the method to display the value.

An Array of Characters

To declare an array of characters, follow the char keyword with aquare brackets and and initialize the variable.

A Byte Type

The Byte Data Type

A byte is an unsigned number whose value can range from 0 to 255 and therefore can be stored in one byte. You can use it when you know a variable would hold a relatively small value. To declare a variable that would hold a small natural number, use the byte keyword. Here is an example:

byte Age;

Use this type of can initialize a byte variable when declaring it or afterwards. Here is an example that uses the byte data type:

class Exercise
{
    static void Main()
    {
        byte age = 14;
        System.Console.Write("Student Age: ");
        System.Console.WriteLine(age);

        age = 12;
        System.Console.Write("Student Age: ");
        System.Console.WriteLine(age);
    }
}

Each one of the characters you see on your keyboard is represented as a numeric value, but whether it appears as a number, a letter, or a symbol, each one of these is considered a character. To let you display a character on the console screen, both the Console.Write() and the Console.WriteLine() methods each has a syntax that takes a char argument. Their syntaxes are:

public static void Write(char value);
public static void WriteLine(char value);

You can initialize a byte variable when declaring it or afterwards. Here is an example that uses the byte data type:

class Exercise
{
    static void Main()
    {
        byte age = 14;
        System.Console.Write("Student Age: ");
        System.Console.WriteLine(age);

        age = 12;
        System.Console.Write("Student Age: ");
        System.Console.WriteLine(age);
    }
}

Make sure you don't use a value that is higher than 255 for a byte variable, you would receive an error. When in doubt, or when you think that there is a possibility a variable would hold a bigger value, don't use the byte data type.

Alternatively, you can also use the var keyword to declare the variable and initialize it with a small number. Here is an example:

class Exercise
{
    static void Main()
    {
        var age = 14;
        System.Console.Write("Student Age: ");
        System.Console.WriteLine(age);

        age = 12;
        System.Console.Write("Student Age: ");
        System.Console.WriteLine(age);
	    System.Console.ReadKey();
    }
}

Instead of a decimal number, you can also initialize an integral variable with a hexadecimal value. When doing this, make sure the decimal equivalent is less than 255. Here is an example:

class Exercise
{
    static void Main()
    {
        var number = 0xFE;

        System.Console.Write("Number: ");
        System.Console.WriteLine(number);
	    System.Console.ReadKey();
    }
}

This would produce:

Number: 254
Press any key to continue . . .

Signed Byte

A byte number is referred to as signed if it can hold a negative or a positive value that ranges from -128 to 127, which can therefore fit in a byte. To declare a variable for that kind of value, use the sbyte keyword. Here is an example:

class Exercise
{
    static void Main()
    {
        sbyte roomTemperature = -88;

        System.Console.Write("When we entered, the room temperature was ");
        System.Console.WriteLine(roomTemperature);
    }
}

This would produce:

When we entered, the room temperature was -88

A Word

Introduction

A word is a group of 16 consecutive bits. The bits are counted from right to left starting at 0:

Considered as a group of 16 bits, the most right bit of a word, bit 0, is called the least significant bit or low order bit or LO bit or LOBIT. The most left bit, bit 15, is called the most significant bit or high order bit or HI bit or HIBIT. The other bits are referred to using their positions: bit 1, bit 2, bit 3, etc.

Considering that a word is made of two bytes, the group of the right 8 bits is called the least significant byte or low order byte or LO byte or LOBYTE. The other group is called the most significant byte or high order byte or HI byte or HIBYTE.

The representation of a word in binary format is 0000000000000000. To make it easier to read, you can group bits by 4, like this: 0000 0000 0000 0000. Therefore, the minimum binary value represented by a word is 0000 0000 0000 0000. The minimum decimal value of a word is 0. The minimum hexadecimal value you can store in a word is 0x0000000000000000. This is also represented as 0x00000000, or 0x0000, or 0x0. All these numbers produce the same value, which is 0x0.

The maximum binary value represented by a word is 1111 1111 1111 1111. To find out the maximum decimal value of a word, you can use the base 2 formula, filling out each bit with 1:

1*215+1*214+1*213 + 1*212 + 1*211 + 1*210 + 1*29 + 1*28 + 1*27 + 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20

= 32768 + 16384 + 8192 + 4096 + 2048 + 1024 + 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1

= 65535

To find out the maximum hexadecimal number you can store in a word, replace every group of 4 bits with an f or F:

1111 1111 1111 1111
f f f f
= 0xffff
= 0xFFFF
= 0Xffff
= 0XFFFF

Short Integers

A word, which is a group of 16 contiguous bits or 2 bytes, can be used to hold a natural number. As we have studied, the maximum numeric value that can fit in a word is 65535. To declare a variable for such a value, you can use the var keyword and initialize the variable with a value between -32768 et 32767. Here is an example:

class Exercise
{
    static void Main()
    {
        var schoolEffective = 1400; // Number of Students

        System.Console.Write("School Effective: ");
        System.Console.WriteLine(schoolEffective);
    }
}

This would produce:

School Effective: 1400
Press any key to continue . . .

Since the byte is used for characters and very small numbers, whenever you plan to use a number in your program, the minimum representation you should use is a word.

A natural number is also called an integer. If you want to declare the variable using a data type, the smallest integer you can store in a word is declared with the short keyword. Because a short integer is signed by default, it can store a value that ranges from -32768 to 32767. Here is an example that uses two short integers:

using static System.Console;

class Exercise
{
    static void Main()
    {
        short numberOfPages;
        short temperature;

        numberOfPages = 842;
        temperature   = -1544;

        Write("Number of Pages of the book: ");
        WriteLine(numberOfPages);
        Write("Temperature to reach during the experiment: ");
        Write(temperature);
        WriteLine(" degrees\n");
    }
}

This would produce:

Number of Pages of the book: 842
Temperature to reach during the experiment: -1544 degrees

Because a short integer handles numbers that are larger than the signed byte, any variable you can declare for a signed byte can also be declared for a short variable.

Unsigned Short Integers

If a variable must hold positive and relatively small numbers, it is referred as an unsigned short integer. Such a variable can be declared using either the var or the ushort keyword. An unsigned short integer can hold numbers that range from 0 to 65535 and therefore can fit in 16 bits. Here are examples:

using static System.Console;

class Exercise
{
    static void Main()
    {
        // These variables must hold only positive integers
        ushort numberOfTracks;
        ushort musicCategory;

        numberOfTracks = 16;
        musicCategory  = 2;

        Write("This music album contains ");
        Write(numberOfTracks);
        WriteLine(" tracks");
        Write("Music Category: ");
        Write(musicCategory);
    }
}

This would produce:

This music album contains 16 tracks
Music Category: 2

Practical LearningPractical Learning: Using Unsigned Integers

  1. To use unsigned variables, change the document as follows:
    using static System.Console;
    
    namespace PayrollPreparation4
    {
        public class AccountCreation
        {
            public static void Main(string[] args)
            {
                ushort digits = 0;
                ushort symbols = 0;
                ushort letters = 0;
                ushort numbers = 0;
                ushort lowercase = 0;
                ushort uppercase = 0;
                ushort separators = 0;
                ushort whiteSpaces = 0;
                ushort punctuations = 0;
                ushort letterOrDigits = 0;
    
                string strUsername = string.Empty;
    
                WriteLine("Account Creation");
                WriteLine("---------------------------------");
                WriteLine("Provide the following information");
                Write("First Name:       ");
                string strFirstName = ReadLine();
                Write("Middle Name:      ");
                string strMiddleName = ReadLine();
                Write("Last Name:        ");
                string strLastName = ReadLine();
                WriteLine("---------------------------------");
                Write("Password:         ");
                string strNewPassword = ReadLine();
                Write("Confirm Password: ");
                string strConfirmPassword = ReadLine();
    
                Clear();
    
                WriteLine("Account Summary");
                WriteLine("----------------------------");
                WriteLine("First Name:      " + strFirstName);
                WriteLine("Middle Name:     " + strMiddleName);
                WriteLine("Last Name:       " + strLastName);
                WriteLine("-------------------------------------------");
    
                if (strMiddleName.Length == 0)
                    strUsername = string.Concat(strFirstName.Substring(0, 1), strLastName).ToLower();
                else
                    strUsername = string.Concat(strFirstName.Substring(0, 1), strMiddleName.Substring(0, 1), strLastName).ToLower();
                WriteLine("Username:        " + strUsername);
    
                if (strNewPassword.Equals(strConfirmPassword))
                {
                    for (int i = 0; i < strNewPassword.Length - 1; i++)
                    {
                        if (char.IsWhiteSpace(strNewPassword, i))
                            whiteSpaces++;
                        if (char.IsLetter(strNewPassword, i))
                            letters++;
                        if (char.IsDigit(strNewPassword, i))
                            digits++;
                        if (char.IsLetterOrDigit(strNewPassword, i))
                            letterOrDigits++;
                        if (char.IsNumber(strNewPassword, i))
                            numbers++;
                        if (char.IsPunctuation(strNewPassword, i))
                            punctuations++;
                        if (char.IsSeparator(strNewPassword, i))
                            separators++;
                        if (char.IsSymbol(strNewPassword, i))
                            symbols++;
                        if (char.IsLower(strNewPassword, i))
                            lowercase++;
                        if (char.IsUpper(strNewPassword, i))
                            uppercase++;
                    }
    
                    WriteLine("Password:        " + strNewPassword);
                    WriteLine("Password Length: {0} symbol(s)/character(s)", strNewPassword.Length.ToString());
                    WriteLine("-------------------------------------------");
                    WriteLine("The password contains:");
                    WriteLine(" " + whiteSpaces + " white space(s)");
                    WriteLine(" " + symbols + " symbol(s)");
                    WriteLine(" " + digits + " digit(s)");
                    WriteLine(" " + letters + " letter(s)");
                    WriteLine(" " + letterOrDigits + " letter(s) or digit(s)");
                    WriteLine(" " + numbers + " number(s)");
                    WriteLine(" " + punctuations + " punctuation mark(s)");
                    WriteLine(" " + separators + " separator character(s)");
                    WriteLine(" " + lowercase + " lowercase letter(s)");
                    WriteLine(" " + uppercase + " uppercase letter(s)");
    
                }
                else
                {
                    WriteLine("The passwords you entered don't match.");
                }
                WriteLine("===========================================");
            }
        }
    }
  2. To execute the program, on the main menu
  3. Type some values as follows (for the middle name, you will simply press Enter):
    Account Creation
    ---------------------------------
    Provide the following information
    First Name:       Richard
    Middle Name:
    Last Name:        Steiger
    ---------------------------------
    Password:         $Tr0ng P@s& W&rd !44
    Confirm Password: $Tr0ng P@s& W&rd !44
  4. Press Enter:
    Account Summary
    ----------------------------
    First Name:      Richard
    Middle Name:
    Last Name:       Steiger
    -------------------------------------------
    Username:        rsteiger
    Password:        $Tr0ng P@s& W&rd !44
    Password Length: 20 symbol(s)/character(s)
    -------------------------------------------
    The password contains:
     3 white space(s)
     1 symbol(s)
     2 digit(s)
     9 letter(s)
     11 letter(s) or digit(s)
     2 number(s)
     4 punctuation mark(s)
     3 separator character(s)
     6 lowercase letter(s)
     3 uppercase letter(s)
    ===========================================
    Press any key to continue . . .
  5. Press Enter to close the DOS window and return to your programming environment
  6. Close your programming environment

Home Copyright © 2008-2019, FunctionX Next