Question

Lab 6.4 Write a C++ program that contain all the following patterns as functions and let the user choose between them by prov
0 0
Add a comment Improve this question Transcribed image text
Answer #1

*****************************************************************************
PLEASE DO UPVOTE IF THE ANSWER IS HELPFUL AS IT GIVES THE CONFIDENCE TO HELP MORE STUDENTS
*****************************************************************************
Chegg allows me to answer specific no of questions including the subparts, so please do post the rest of the questions as a separate query as per Chegg Guidelines. Thank you :)
*****************************************************************************

#include <iostream>

using namespace std;

void upward(int n)

{

char x[2*n-1][2*n-1];

for(int i=0;i<2*n-1;i++)

{

for(int j=0;j<2*n-1;j++)

{

x[i][j]=' ';

}

}

for(int i=0;i<2*n-1;i++)

{

x[i][0]='*';

}

for(int i=0;i<n-1;i++)

{

x[i][i]='*';

}

for(int i=n-1;i<2*n-1;i++)

{

x[i][2*n-i-2]='*';

}

for(int i=0;i<2*n-1;i++)

{

for(int j=0;j<2*n-1;j++)

{

cout<<x[i][j]<<" ";

}

cout<<endl;

}

}

void downward(int n)

{

for(int i=0;i<n-1;i++)cout<<" ";cout<<" *";cout<<endl;

n= n-1;

for(int i=n-1;i>=0;i--)

{

int j= n-i;

for(int k=0;k<i;k++)cout<<" ";cout<<"*";

for(int k=0;k<j;k++)cout<<" ";cout<<"*";

cout<<endl;

}

for(int i=1;i<n;i++)

{

int j= n-i;

for(int k=0;k<i;k++)cout<<" ";cout<<"*";

for(int k=0;k<j;k++)cout<<" ";cout<<"*";

cout<<endl;

}

for(int i=0;i<n;i++)cout<<" ";cout<<" *";

cout<<endl;

}

int main() {

int n ;

cin>>n;

upward(n);

downward(n);

  return 0;

}

1 #include <iostream> using namespace std; 2 3 } clang++-7 -pthread -std=c++11 -o main ma: П.cpp } ./main 5 4 5 6 void upward

35 void downward (int n) 36 { > clang++-7 -pthread -std=c++11 -o main mai n.cpp } ./main 5 37 38 39 40 41 42 43 for(int i=0;i

Add a comment
Know the answer?
Add Answer to:
Lab 6.4 Write a C++ program that contain all the following patterns as functions and let...
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
  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program...

    Write in C. Simple Program (beginner) Assignment: Write a program Character Pointers and Functions. (like program #5-5). Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count. <END>

  • Write a program which uses four functions [ 1 for each part of the assignment ]:...

    Write a program which uses four functions [ 1 for each part of the assignment ]: 1. Display all numbers between 1 and n, where n is an input from the user. 2. Display the reverse of a number n, where n is input from the user. 3. Display the following pattern for n rows, where n is input from the user: (ON PYTHON IDLE 3.7.2) Again, define a function for each part of the assignment, define a mainO function...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Write a program that takes these values to find all of the different patterns in "input"...

    Write a program that takes these values to find all of the different patterns in "input" of length "patternLength" and output all of the patterns that occur more than once and the number of times they occur. For example, when searching the string "zf3kabxcde224lkzf3mabxc51+crsdtzf3nab=", with a specified pattern length of 3, the method should return the pattern "abx” with an occurrence value of two, and “zf3” with an occurrence value of three. The answer should be written in C#,

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • **IN C*** * In this lab, you will write a program with three recursive functions you...

    **IN C*** * In this lab, you will write a program with three recursive functions you will call in your main. For the purposes of this lab, keep all functions in a single source file: main.c Here are the three functions you will write. For each function, the output example is for this array: int array[ ] = { 35, 25, 20, 15, 10 }; • Function 1: This function is named printReverse(). It takes in an array of integers...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

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