Question

1. Modify the program to output that line N times. That is, output a square of N lines each with N characters. Example output

Eusing System; using System.Collections.Generic; using System.Text; 1 2 3 4 5 6 namespace Pracpi { Oreferences public class P

C# Visual Studio

using System;
using System.Collections.Generic;
using System.Text;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the code in C# for the above question:

*********************** 1. ***********************

using System;
using System.Collections.Generic;
using System.Text;


namespace PracP1
{
public class Program
{
public static void Main(string[] args)
{
int n = 0;
string s = "";

// check if 2 arguments
if(args.Length == 2)
{
if(int.TryParse(args[0],out n))
{
// successful parse to use n
s = args[1]; // Second argument is character
// draw a line of characters
DrawChars(n, s);
}
else
{
// Unsuccessful parse so no n value
}
}

// Wait for user to have read the output.
Console.WriteLine();
Console.Write("<Press enter to finish>");
Console.ReadLine();
}

static void DrawChars(int n,string s)
{
// this gives the square of n lines each with n character s
for(int i=0;i < n; i++)
{
for(int j=0;j< n; j++)
{
Console.Write(s);
}
Console.WriteLine();
}
Console.WriteLine();
}
}
}

*********************** 2. ***********************
using System;
using System.Collections.Generic;
using System.Text;

namespace PracP1
{
public class Program
{
public static void Main(string[] args)
{
int n = 0;
string s = "";

// check if 2 arguments
if(args.Length == 2)
{
if(int.TryParse(args[0],out n))
{
// successful parse to use n
s = args[1]; // Second argument is character
// draw a line of characters
DrawChars(n, s);
}
else
{
// Unsuccessful parse so no n value
}
}

// Wait for user to have read the output.
Console.WriteLine();
Console.Write("<Press enter to finish>");
Console.ReadLine();
}

static void DrawChars(int n,string s)
{
// integer variable k that keep track of line number
int k = 1;
for(int i=1;i <= n; i++)
{
for(int j=1;j<= n; j++)
{
// if j is equal to i then print the number k
if (j == i)
{
Console.Write(k);
}
// else print the character.
else
{
Console.Write(s);
}

}
// incrementing k by 1.
k++;
// if k becomes greater than 9 then set k to 0.
if (k > 9) k = 0;
Console.WriteLine();
}
Console.WriteLine();
}
}
}

Refer to the screenshot attached below to better understand the code and indentation:

*********************** 1. ***********************

şusing System; using System.Collections.Generic; using System.Text; B namespace PracP1 { O references public class Program {
// wait for user to have read the output. Console.WriteLine(); Console.Write(<Press enter to finish>); Console.ReadLine();

*********************** 2. ***********************
Gusing System; using System.Collections.Generic; using System.Text; namespace PracP1 { O references public class Program n- {
Console.ReadLine(); } E { 1 reference static void Drawchars(int n,string s) // integer variable k that keep track of line num

Output:

1. N = 5 and S = "*"

轉轉轉轉轉 轉轉 彎彎 彎彎 專灣灣彎 轉轉轉轉轉

2. N = 11 ans S = "*"
*2家家家家家家家家 **3家家家家 4來 家事5多家, 家家家6 家家等了多家家 《家家等8家家家 家家来四来家 家家事 《原来1

If this answer helps you then please upvote,
for further queries comment below.
Thank you.

Add a comment
Know the answer?
Add Answer to:
C# Visual Studio using System; using System.Collections.Generic; using System.Text; 1. Modify the program to output that...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;...

    ==Modify the M8B by using C#== using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace M8B {     class Magic8Ball     {         static void Main(string[] args)         {             string question;             Console.WriteLine("I am the Magic 8-ball! Ask me a question and I will give you an answer.");             Console.Write("Your question: ");             question = Console.ReadLine();             Console.WriteLine("\nLet me part the mists of the time for you.");             Random rnd = new Random();             int roll =...

  • Fix program errors and improve code Visual Studio C# Console App (.NET Framework) Task The program...

    Fix program errors and improve code Visual Studio C# Console App (.NET Framework) Task The program must allow for the teacher to either enter a predetermined number of scores (e.g. 10 exam scores), to keep allowing them to enter in scores until they are finished. You will need to convert these scores to a percentage then store these in a list. You will perform some calculations on these results and also display the contents of the list (percentage values) back...

  • 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 namespace ConsoleApplication1 6...

    1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 namespace ConsoleApplication1 6 { class Program { 9 static void Main(string[] args) 10 { 11 test t = new test(10); Console.WriteLine(t. Getio); Console.WriteLine(t.J); 14 } 15 } 16 class test 17 { 18 18 private int i; 19 private int j; 20 public test(int a) 21 { 22 i = a; 23 j = a +5; public int Getio return i; } public int ) 29 30...

  • (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example,...

    (C#, Visual Studio) I need help modifying my program code to accommodate repeated numbers. For example, if a user inputs a repeated number the program should regenerate or ask to enter again. If needed, here is the program requirements: Create a lottery game application. Generate four random numbers, each between 1 and 10. Allow the user to guess four numbers. Compare each of the user’s guesses to the four random numbers and display a message that includes the user’s guess,...

  • Create a C# program in visual studios called FortuneCookie whose Main() method contains an array of...

    Create a C# program in visual studios called FortuneCookie whose Main() method contains an array of at least 8 strings with fortune-telling phrases. The program should randomly select 2 different phrases and pass them to a method that displays them. A random number generator should be used to select the phrases from random positions in the array and the length of the array should be used to determine one of the random number generator range boundaries (i.e., do not hardcode...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • In C programming language: This program will output a right triangle based on user specified height...

    In C programming language: This program will output a right triangle based on user specified height triangleHeight and symbol triangleChar. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangleChar character. (1 pt) (2) Modify the program to use a nested loop to output a right triangle of height triangleHeight. The first line will have one user-specified character, such as % or *....

  • You must first compile both .cs file into .exe. Then, run the server in one command...

    You must first compile both .cs file into .exe. Then, run the server in one command prompt window and run two cilents, each in a separate command prompt window. To quit a client, you may enter no book title but just hit the enter or enter Ctrl-C. The server always displays a message whenever a client is connected and disconnected. <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key = "U101" value="PHYSICS"/> <add key = "U102" value="EDU"/> <add key = "U103"...

  • Complete a program In C#: some code is included, you edit the areas that have not...

    Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...

  • Modify the program so that it uses a loops repeatedly doing: • prompt for input (using...

    Modify the program so that it uses a loops repeatedly doing: • prompt for input (using line seqNum and the prompt phrase: "Enter a line") • reads the line of input • stores the line of input in the next position of an array of Line or an ArrayList of Line. Once the user enters STOP as input, the loop should terminate and another loop should print each line in reverse order. For example (the input you should type in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT