QuestionQuestion

Transcribed TextTranscribed Text

(1) Star patterns Star patterns are patterns using asterisks -*", to create specific shape, e.g., square, triangle(pyramid), rhombus etc. Write a C code that takes a character C as shape value and an integer n as the size of the shape and output that specific shape using asterisk ****** of size n. Following is the list of shapes and associated character inputs you need to implement. Write separate function to print each shape. Shape Name Associated Character Example patterns for n = 5 Hollow Square S Hollow r Rhombus Hollow p Pyramid Diamond d Cross c (2) Variable Pricing Variables, a new bar, has a very unusual pricing policy for the two drinks that it sells (called A and B here for simplicity). At the start of each night, each drink costs $5. Each time a drink is purchased, its price goes up $1 for the next patron (the prices change independently; if someone purchases drink A, its price goes up but the price for B stays the same). In order to prevent prices from getting too high, a drink's price cannot exceed $11; after a drink is sold for $11, its price resets back to $5 and begins to rise again. For example, suppose several drinks are purchased in the following order: A, A, A, B, B, A, B. The corresponding prices for these drinks (in order) would be $5, $6, $7, $5, $6, $8, $7. Write a C program, which reads in a sequence of drink orders from the user (as a series of capital As and Bs, with no spaces or other characters). Your program should print out the total cost of all the drinks sold (in the example above, the total cost would be $44). Sample Input: AAABBAB Sample Output: 44 Hint: Your program must be able to accept a sequence of drink orders of any length, so a while loop with getchar () would probably be the best strategy here. (3) Perfect number A perfect number is a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1+2+3. Write a function is Per fect to check if a number is a perfect number. If the number is perfect the function returns true otherwise false. Write a test code which takes a number n as input and Output whether it is a perfect number or not. (i) Sample Input: 6, Sample Output: 6 is a perfect number (ii) Sample Input: 10, Sample Output: 10 is not a perfect number

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

// Libraries included
#include <stdio.h>

// Declare the five functions with the shapes
void hollowSqr(int x);
void hollowRho(int x);
void hollowPyr(int x);
void filledDia(int x);
void xCross(int x);

// Main Function
int main()
{
// Declaring and setting variables
int x=0;
char sha;

// Prompt the user to enter the letter corresponding shape
printf("\nHollow Square - s");
printf("\nHollow Rhombus - r");
printf("\nHollow Pyramid - p");
printf("\nFilled in Pyramid - d");
printf("\nX-Cross - c");
printf("\nPick from the following shapes: ");
scanf("%c", &sha);

// Prompt the user to enter the length or number
printf("\nEnter the length: ");
scanf("%d", &x);

// Checks for the letter and prints out the shape accordingly
switch (sha) {
case 's':
{
// Calls Hollow Square Function
hollowSqr(x);
break;
}
case 'r':
{
// Calls Hollow Rhombus Function
hollowRho(x);
break;
}
case 'p':
{
// Calls Hollow Pyramid Function
hollowPyr(x);
break;
}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$10.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats