/* C program that uses menus to enter choices to print a filled
square, empty square,filled triangle,
empty triangle, and zigzags*/
#include<stdio.h>
#include<stdlib.h>
//function prototypes
void fillSquare(int size);
void emptySquare(int size);
void fillTriangle(int size);
void emptyTriangle(int size);
void zigzag(int,int);
//main()
int main()
{
int shape,size,fill,zigs;
while(1)
{
printf("\n\nEnter shape (1) Square,
(2) Triangle, (3) Zig-zag , (4) Quit : ");
scanf("%d",&shape);
//choices
switch(shape)
{
case 1: // case
-1 for square
printf("\nEnter size : ");
scanf("%d",&size);
printf("\nEnter (0) No fill, (1) Fill :
");
scanf("%d",&fill);
if(fill==0)
emptySquare(size);
if(fill==1)
fillSquare(size);
break;
case
2: // case -1 for triangle
printf("\nEnter size : ");
scanf("%d",&size);
printf("\nEnter (0) No fill, (1) Fill :
");
scanf("%d",&fill);
if(fill==0)
emptyTriangle(size);
if(fill==1)
fillTriangle(size);
break;
case
3: // case -1 for
zigzags
printf("\nEnter size : ");
scanf("%d",&size);
printf("\nEnter number of zigs : ");
scanf("%d",&zigs);
zigzag(size,zigs);
break;
case 4:
exit(0);
}
}
return 0;
}
//this method prints a filled square of given size
void fillSquare(int size)
{
int i,j;
printf("\n");
for(i=1;i<=size;i++)
{
for(j=1;j<=size;j++)
{
printf("*");
}
printf("\n");
}
}
//this method prints a empty square of given size
void emptySquare(int size)
{
int i,j;
printf("\n");
for(i=1;i<=size;i++)
printf("*");
for(i=2;i<size;i++)
{
printf("\n*");
for(j=2;j<size;j++)
{
printf(" ");
}
printf("*");
}
printf("\n");
for(i=1;i<=size;i++)
printf("*");
}
//this method prints a filled triangle of given size
void fillTriangle(int size)
{
int i,j;
printf("\n");
for(i=1;i<=size;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}
//this method prints a empty traingle of given size
void emptyTriangle(int size)
{
int i,j;
printf("\n*");
for(i=2;i<size;i++)
{
printf("\n*");
for(j=2;j<i;j++)
{
printf(" ");
}
printf("*");
}
printf("\n");
for(i=1;i<=size;i++)
printf("*");
}
//this method prints a zigs zage of given size and number of
zigs
void zigzag(int size,int zigs)
{
int k,i,j;
for(k=1;k<=zigs;k++)
{
printf("\n");
for(i=1;i<=size;i++)
{
for(j=1;j<i;j++)
printf(" ");
printf("*");
printf("\n");
}
for(i=1;i<=size;i++)
{
for(j=1;j<=4-i;j++)
printf(" ");
printf("*");
printf("\n");
}
}
}
---------------------------------------------------------------------------------
outputs below
For this lab you will write a small program that prints a few "shapes" using asterisks....
Use Python and only while loops For this part of the homework you will write code to draw an isosceles right triangle. (A right triangle in which the height and base are the same size.) Your program should prompt the user for these inputs, in exactly this order: 1. The height of their triangle 2. The symbol the triangle will be outlined in 3. The symbol the triangle will be filled with For these inputs, you can assume the following:...
1. (30 Points) Write a MATLAB program that displays "The multiplication of 10 multiplied by integers of 1 through 15. Display your result back to the user with 2 decimal places (yes, 2 decimal places). You must implement your code using a for loop. The result should have the following format: The multiplication of 10*1 =10.00 The multiplication of 10*2 =20.00 The multiplication of 10'3=30.00 The multiplication of 10*15=150.00 2. (35 Points) Write MATLAB code to prompt a user for...
Write a program called draw_shapes.py. In your program, Create a block header with: your name the date a short description of what the program does: Assignment 5: Draw shapes using turtle Import the turtle module. Create a window and screen (canvas) where your turtle will draw. Make the window 400 pixels wide x 400 pixels high and give it an indigo background and a title of "Shapes". Use this code to create a window object: # a place for the...
What if you had to write a program that would keep track of a list of rectangles? This might be for a house painter to use in calculating square footage of walls that need paint, or for an advertising agency to keep track of the space available on billboards. The first step would be to define a class where one object represents one rectangle's length and width. Once we have class Rectangle, then we can make as many objects of...
This assignment requires you to write a program to implement an odd-order Magic Square. Prompt the user to enter the “order” of the square and then produce for the user a magic square of that order. Run your code for at least four different inputs – all odd. ODD ORDER MAGIC SQUARES 1. Start by placing 1 in the middle column of the top row. 2. Continue by always placing the next number (say k+1) in the square diagonally up...
Today you are to write a Java program that will prompt for and read 2 words of equal length entered by the user, and create a new word which contains the last letter of the 1st word, the last letter of the 2nd word, followed by the second to last character of the 1st word, followed by the second to last character of the 2nd word and so on. Be sure to use the same format and wording as in...
Overview: In this lab, you will write a program called JobScheduler; it should take a single input file as a command-line argument. Each line in the input file has the following format: <job #> <priority> <arrival time (sec)> <duration (sec)> e.g. a file might contain: 1 3 10 100 5 2 20 50 8 4 5 100 (all values will be positive integers) These jobs might represent computer programs (or threads) that need to be run by the operating system....
Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...
For this lab you will be creating a class representing the shape square. A Square is a special case of a Rectangle where both sides have the same length. Rectangle has been provided for your use in this lab. A Rectangle has a height and a width as member variables, two constructors, two member functions, area() and perimeter(), and lastly, an input and output operator. Your Square class should publicly inherit from Rectangle. You will need to update the Constructors...
C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....