Question

Lab 03 Numbers Squared and Rotated! Objective: Write a program that prompts the user for a...

Lab 03

Numbers Squared and Rotated!

Objective:

Write a program that prompts the user for a 4-digit whole number (we assume the users will enter this correctly) and then displays it squared! No, not the mathematical squaring. This will make a square box of the numbers! WHOA! The top is the number, the left-hand side is the number but going down, the bottom is the number reversed, and the right hand side is the number going up. Also once the number is squared it is rotated clockwise by one space, and then again. HINT: While it seems like this should be stored as a numeric value (int or double) it may make more sense to store it as a String and use String methods.

Example Dialog:

Enter a 4-digit number

1234

The number squared is:

1234

2 3

3 2

4321

The number squared rotated clockwise one space is:

2123

3 4

4 3

3212

The number squared rotated clockwise again is:

3212

4 3

3 4

2123

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include<string>
using namespace std;

void printMatrix(char s[]){
for(int i = 0 ; i< 4 ; i++){
cout<<s[i];
}
cout<<endl;
  
cout<<s[11]<<" "<<s[4]<<endl;
cout<<s[10]<<" "<<s[5]<<endl;
  
for(int i = 9 ; i>5 ;i--){
cout<<s[i];
}
cout<<endl;
}


int main()
{
cout<<"Enter a 4-digit number"<<endl;
char s[12];
cin>>s;
s[4] = s[2];
s[5] = s[1];
s[6] = s[0];
s[7] = s[1];
s[8] = s[2];
s[9] = s[3];
s[10] = s[2];
s[11] = s[1];
cout<<"The number squared is:\n";
printMatrix(s);

//1st rotation
int temp = s[11];
for(int i = 11; i >0 ; i--){
s[i] = s[i-1];
}
s[0] = temp;
cout<<"The number squared rotated clockwise one space is:\n";
printMatrix(s);

//2nd rotation
temp = s[11];
for(int i = 11; i >0 ; i--){
s[i] = s[i-1];
}
s[0]=temp;
cout<<"The number squared rotated clockwise again is:\n";
printMatrix(s);

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Lab 03 Numbers Squared and Rotated! Objective: Write a program that prompts the user for a...
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
  • c++ Write a program that prompts the user to enter a length in feet and then...

    c++ Write a program that prompts the user to enter a length in feet and then enter a length in inches and outputs the equivalent length in centimeters. If the user enters a negative number or a non-digit number, throw and handle an appropriate exception and prompt the user to enter another set of numbers. Your error message should read A non positive number is entered and allow the user to try again.

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. ​ 1 largest = None 2 smallest = None 3 while True: 4...

  • Write a program that prompts the user to enter the number of milliseconds and converts the milliseconds to a string hours:minutes:seconds

    Problem 1.Write a program that prompts the user to enter the number of milliseconds and converts the milliseconds to a string hours:minutes:seconds. The program should use the convertMillismethod with the following header:public static String convertMillis(long millis)For example, convertMillis(5500) returns the string 0:0:5, convertMillis(100000) returns the string 0:1:40, andconvertMillis(555550000) returns the string154:19:10.Problem 2. (Count occurrence of numbers)Write a program that reads integers between 1 and 100 and counts the occurrence of each (you should store the numbers in an array). Output...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

  • write an 8086 assembly program that performs the following functions: Prompts the user to enter a set of student’s lab grades (array of 2-digit decimal numbers) and store it in the memory. Use ‘$’ sign as termination, i.e., the user enters ‘$’ at the end

    write an 8086 assembly program that performs the following functions: Prompts the user to enter a set of student’s lab grades (array of 2-digit decimal numbers) and store it in the memory. Use ‘$’ sign as termination, i.e., the user enters ‘$’ at the end of the numbers. You can assume that the maximum number of students in the lab is 20.

  • How to write this code in C++???? using fstream Write a program which: Asks the user...

    How to write this code in C++???? using fstream Write a program which: Asks the user to enter a positive integer greater than 0 Validates that the entry is a positive integer Outputs the digits in reverse order with a space separating the digits Outputs the even digits not in reverse order with a space separating the digits (consider zero to be even) If there are no even digits, the an appropriate message should be displayed: There are no even...

  • MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers....

    MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers. Then prompt the user again to input as many numbers as they choose. Stop the program by inputting-1. Then, display the largest number and second largest number in the command window once the user kills the program. The built-in max function cannot be used. The figure below is an example of what the command window should look like when the code is ran. First...

  • IN SPARC ASSEMBLY ONLY, write a program that prompts the user for two numbers and prints...

    IN SPARC ASSEMBLY ONLY, write a program that prompts the user for two numbers and prints the sum. THIS MUST BE IN SPARC ASSEMBLY. DO NOT WRITE IT IN NORMAL ASSEMBLY LANGUAGE. Sample: Enter Number 1: 2 Enter Number 2: 3 The sum of 2 and 3 is 5 Note: -Your program should contain .data, .bss, and .text sections -DO NOT try to optimize your code (i.e remove nops) -DO NOT write this in regular assembly, it must be in...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

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