ProgrammingCan someone help me with some simple C# Questions?Posted:

fest
  • Halloween!
Status: Offline
Joined: Sep 05, 20127 Year Member
Posts: 1,483
Reputation Power: 182
Sup boys, i have some super easy c# sharp questions i need to know the answers to.

If you help me out you'll get +rep and potential donation from me via pp (im pretty sure thats not allowed but what ever.)

heres the questions in each spoiler, they're pretty simple btw too

Question 1


Write a program which squares the values in a list entered by the user and then finds the sum.

Sample sessions:

I will square the numbers in a list and add them all up. Enter a comma separated list of numbers: 1, 2, 3 The result of the calculation is: 14

I will square the numbers in a list and add them all up. Enter a comma separated list of numbers: 2, 4, 6 The result of the calculation is: 56

I will square the numbers in a list and add them all up. Enter a comma separated list of numbers: 0, 3, 5, 7 The result of the calculation is: 83



Question 2


Question #7 [weight 2]

Write a program which opens a file containing lists of numbers, calculates the sum of each list, and outputs a file containing the sums of the lists.

Input File (named input.txt) Output File (named output.txt)

1,3,4,5,6,7,8,9,0,2,3,4,5

9,5,4,6,5,2,3,4,5,6,7,8,9,2,3,1

3,3,5,5,7,5,2,2,1,4,3

9,8,9,8,6,5,4,3,2

3,4,3,2,1,6,7,8,7,5,9,9,0,1 57 79 40 54 65



Question 3


Write a program which draws an asterisk staircase to the console window. The user enters the size of the stairs to be rendered.

Enter the base of the stairs: 3 * ** ***

Enter the base of the stairs: 4 * ** *** ****

Enter the base of the stairs: 5 * ** *** **** *****



Question 4, similar to 3


Modify your code from the previous question to draw the staircases backwards.

Enter the base of the stairs: 3 * ** ***

Enter the base of the stairs: 4 * ** *** ****

Enter the base of the stairs: 5 * ** *** **** *****



Question 5


Write a program which generates random 5-letter fantasy names. The first, third, and fifth letter must be consonants and the second and fourth letters must be vowels. Include y as a consonant.

Here is some sample output:

How many names would you like to generate? 10 xaril rumon zumiw yayah negop revez xovog vojeh linaq zepof

#2. Posted:
CriticaI
  • 2 Million
Status: Offline
Joined: Nov 05, 20136 Year Member
Posts: 2,672
Reputation Power: 154
This looks like homework. You would be better off doing it yourself. You could learn a thing or two. If it is not homework, then what is the question?
#3. Posted:
-Deano
  • Rated Awesome
Status: Offline
Joined: Aug 19, 20109 Year Member
Posts: 5,182
Reputation Power: 520
Bit of a bump on this but I assume this homework deadline has passed and I thought the last question was pretty good 'fizz buzz' kind of question.


static void Main(string[] args)
        {
            const string CONSONANTS = "BCDFGHJKLMNPQRSTVWXYZ";
            const string VOWELS = "AEIOUY";

            Console.WriteLine("Press to generate name (X to exit)");

            Random rand = new Random();

            while (Console.ReadKey().Key != ConsoleKey.Escape)
            {
                Console.Write("\b");
                string name = "";
                for (var i = 0; i < 5; i++)
                {
                    if (i % 2 == 0)
                    {
                        name += CONSONANTS[rand.Next(CONSONANTS.Length)];
                    }
                    else
                    {
                        name += VOWELS[rand.Next(VOWELS.Length)];
                    }
                }
                Console.WriteLine(name);
            }
        }
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS