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 =...

  • 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,...

  • 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...

  • 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"...

  • 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 *....

  • 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...

  • Fix the code using C# shown below to show the repitition as seen on the example...

    Fix the code using C# shown below to show the repitition as seen on the example screenshot: (Invalid error must repeat): using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program { class Program { static void Main(string[] args) { double num, count = 0; double Tax = 0.00, ship = 5.00, sum = 0.00; double grandtotal; char line; //Set run =true bool run=true; do { //read amount of item Console.WriteLine("What is the amount of item : "); //read in...

  • C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

  • Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** *...

    Java class quiz need help~ This is the Backwards.java code. public class Backwards { /** * Program starts with this method. * * @param args A String to be printed backwards */ public static void main(String[] args) { if (args.length == 0) { System.out.println("ERROR: Enter a String on commandline."); } else { String word = args[0]; String backwards = iterativeBack(word); // A (return address) System.out.println("Iterative solution: " + backwards); backwards = recursiveBack(word); // B (return address) System.out.println("\n\nRecursive solution: " +...

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
ADVERTISEMENT