Question

In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that...

  1. In C# using the Console App (.NET FRAMEWORK) Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to the next line. A statement of the form Console.Write(" "); can be used to display a space for the last two patterns. There should be no other output statements in the application, other than labeling each pattern.
  2. The application's output should look like the following:

    Pattern A
    
    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    
    Pattern B
    
    **********
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
    
    Pattern C
    
    **********
     *********
      ********
       *******
        ******
         *****
          ****
           ***
            **
             *
    
    Pattern D
    
             *
            **
           ***
          ****
         *****
        ******
       *******
      ********
     *********
    **********
    

    Remember, use Debug, Start Without Debugging (CTRL-F5) to run your Console application.
  3. For Pattern C and Pattern D, you will need TWO loops (one after the other) nested inside your outer loop. The first loop will produce a certain number of spaces. The second loop will produce a certain number of stars. One of these numbers will be the current value of your outer loop's control variable. The other number must be calculated using ALGEBRA. Consider, how many spaces and stars are being output on each row? Always the same amount (here, 10 or MAX_ROWS, if using the same named constant as in the PowerPoint slide code given for Pattern A). So,

    (# spaces) + (# stars) = MAX_ROWS

    This equation is easy to solve for the number of spaces needed (assuming your outer loop control variable represents that number of stars per row, as in the PowerPoint slide code given for Pattern A):

    (# spaces) = MAX_ROWS - (# stars)

    or

    (# spaces) = MAX_ROWS - row

    if you name your variables as in the PowerPoint slide code given for Pattern A. So, you can make your first nested loop start at 1 and count up to (MAX_ROWS - row), outputting a single space on each iteration.

Homework Answers

Answer #1

Program:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Patterns
{
class Program
{
static void Main(string[] args)
{
const int MAX_ROWS = 10;
Console.WriteLine("Pattern A\n");
for (int i = 1; i <= MAX_ROWS; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}

Console.WriteLine("\nPattern B\n");
for (int i = MAX_ROWS; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}

Console.WriteLine("\nPattern C\n");
for (int i = 1; i <=MAX_ROWS; i++)
{
for(int sp=i;sp>1;sp--)
{
Console.Write(" ");
}
for (int j = MAX_ROWS ; j >i; j--)
{
Console.Write("*");
}
Console.WriteLine();
}

Console.WriteLine("\nPattern D\n");
for (int i = 1; i <= MAX_ROWS; i++)
{
for (int sp = MAX_ROWS-1; sp>=i; sp--)
{
Console.Write(" ");
}
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}

Console.ReadKey();
}
}
}

Output:

Know the answer?
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
Similar Questions
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the following problem: The heating system in a school should be switched on if the average temperature is less than 17 degrees Celsius. The average temperature is found from the temperatures in the Math, English and IT departments. You are required to write a program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
--USING C# ONLY-- You will create your own on-line shopping store in the console application. You...
--USING C# ONLY-- You will create your own on-line shopping store in the console application. You can choose different products to sell in your store (at least 8 products). You will create an product inventory text file. The program will display two options at the beginning of the program, Customer and Manager. Customer: If this is a new customer, the program will allow the customer to register with their information and assign a unique ID number to the new customer....
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private...
C# Step 1: Create a Windows Forms Application. Step 2: Create a BankAccount class. Include: Private data fields to store the account holder's name and the account balance A constructor with 0 arguments A constructor with 1 argument (account holder's name) A constructor with 2 arguments(account holder's name and account balance) Public properties for the account holder's name and the account balance. Do not use auto-implemented properties. A method to increase the balance (deposit) A method to decrease the balance...
You've been hired by Text Turtles to write a C++ console application that determines the reading...
You've been hired by Text Turtles to write a C++ console application that determines the reading grade level of the text in a file. The text comes from two files: SampleText1.txt and SampleText2.txt. Sample text1= It has often been said there's so much to be read you never can cram all those words in your head. So the writer who breeds more words than he needs is making a chore for the reader who reads. That's why my belief is...
The second assignment will use C++ syntax and control flow stuctures (e.g. loops, switch statements, functions,...
The second assignment will use C++ syntax and control flow stuctures (e.g. loops, switch statements, functions, const int variables, structs, the standard library, enums, array, etc.) to create a pattern drawing application. A user of your application will be able to select a shape to draw that will be printed out to standard output using std::cout. This application will draw a fixed size 8x8 pattern. The patterns your application will support are: filled, half-left filled, banded, checkered, a square, an...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table....
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table. SQL provides two different techniques for querying data from multiple tables: • The SQL subquery • The SQL join As you will learn, although both work with multiple tables, they are used for slightly different purposes. We used WMCRM database which is what we created in Lab 4. Here is the summary of the database schema (where schema is used in its meaning of...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...