Question

In: Computer Science

In Physics, Mathematics, and related fields, a wave is a disturbance of one of more fields...

In Physics, Mathematics, and related fields, a wave is a disturbance of one of more fields such that the field values oscillate repeatedly about a stable equilibrium value. Waves are usually represented using mathematical functions of the form F (x, t), where x = position and t = time.

Your task is to write a program that will visualize a given wave for exactly N seconds. You do not need to worry about evaluating the mathematical function F(x,t), as the wave will be given to you using its sample representation.

The sample representation of a wave is a series of points that represents the result of the F(x,t) function at each given t. In this problem, you will be given N samples (one for each second) represented by N integers Yi, which represents the vertical coordinate of the wave at time i.

Format Input

The first line contains a single integer N, the number of seconds you need to visualize the wave for. The next line contains N integers Y1, Y2, · · · , Yn as described in the problem statement.

Format Output

Visualize the wave given in the input. The wave should be visualized using a rectangle N characters long and 9 characters tall. Coordinates where the wave is currently in should be represented using the # (hash) character whilst empty coordinates should be represented using the . (dot) character. For clarity, please refer to the sample output section.

Constraints

• 1 ≤ N ≤ 104 • 1≤Yi ≤9

Sample Input 1 (standard input)

9

1 2 3 4 5 6 7 8 9

Sample Output 1 (standard output)

........#

.......#.

......#..

.....#...

....#....

...#.....

..#......

.#.......

#........

Solutions

Expert Solution

JAVA VERSION:

import java.util.*;
public class Main
{
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       System.out.println("Constraints: \n 1≤N≤104 \n 1≤Yi≤9");
       int N; // Declaring N for number of seconds
   while(true){
  
       N=sc.nextInt();
       if(N<1 || N>104) // Checking for correct input
       System.out.println("Value of N exceeds limits. Please enter again");
       else
       break;
   }
       int Y[]=new int[N]; // Declaring array of Yi for vertical positions
       for(int i=0;i<N;i++)
       {
         
       while(true)
       {
       Y[i]=sc.nextInt();
         
       if(Y[i]<1 || Y[i]>9) // Checking for correct input
       System.out.println("Value of N exceeds limits. Please enter again");
   else
      break;
       }
       }
       // Outer loop to print the position for the given number of seconds
       for(int i=0;i<N;i++)
       {
       // Inner loop to print the vertical position of the particle in the space
       for(int j=1;j<10;j++)
       {
       if(j==(10-Y[i])) // If particle postion is same the prints '#'
       System.out.print("#");
       else // If empty postion the print '.'
       System.out.print(".");
       }
       // For going into the next line
       System.out.println();
       }
      
   }
}

----------------------------------------------------------------------------------------------------------------------

C++ VERSOIN:

#include <iostream>

using namespace std;

int main()
{
cout<<"Constraints: \n 1≤N≤104 \n 1≤Yi≤9\n";
int N; // Declaring N for number of seconds
   while(1){
  
       cin>>N;
       if(N<1 || N>104) // Checking for correct input
   cout<<"Value of N exceeds limits. Please enter again\n";
       else
       break;
   }
  
   int Y[N]; // Declaring Yi for vertical positions
       for(int i=0;i<N;i++)
       {
         
       while(1)
       {
       cin>>Y[i];
         
       if(Y[i]<1 || Y[i]>9) // Checking for correct input
          cout<<"Value of N exceeds limits. Please enter again\n";
       else
       break;
       }
       }
      
       // Outer loop to print the position for the given number of seconds
       for(int i=0;i<N;i++)
       {
       // Inner loop to print the vertical position of the particle in the space
       for(int j=1;j<10;j++)
       {
       if(j==(10-Y[i])) // If particle postion is same the prints '#'
       cout<<"#";
       else // If empty postion the print '.'
       cout<<".";
       }
       // For going into the next line
       cout<<"\n";
       }

return 0;
}

-----------------------------------------------------------------------------------------------------------------------

C CODE:

#include <stdio.h>

int main()
{
printf("Constraints: \n 1≤N≤104 \n 1≤Yi≤9\n");
int N; // Declaring N for number of seconds
while(1){
  
scanf("%d",&N);
if(N<1 || N>104) // Checking for correct input
printf("Value of N exceeds limits. Please enter again\n");
else
break;
}
int Y[N]; // Declaring Yi for vertical positions
for(int i=0;i<N;i++)
{

while(1)
{
scanf("%d",&Y[i]);

if(Y[i]<1 || Y[i]>9) // Checking for correct input
printf("Value of N exceeds limits. Please enter again\n");
else
break;
}
}
  
// Outer loop to print the position for the given number of seconds
for(int i=0;i<N;i++)
{
// Inner loop to print the vertical position of the particle in the space
for(int j=1;j<10;j++)
{
if(j==(10-Y[i])) // If particle postion is same the prints '#'
printf("#");
else // If empty postion the print '.'
printf(".");
}
// For going into the next line
printf("\n");
}

return 0;
}

OUTPUT:


Related Solutions

C Programming Language Title : Making wave In Physics, Mathematics, and related fields, a wave is...
C Programming Language Title : Making wave In Physics, Mathematics, and related fields, a wave is a disturbance of one of more fields such that the field values oscillate repeatedly about a stable equilibrium value. Waves are usually represented using mathematical functions of the form F (x, t), where x = position and t = time. Your task is to write a program that will visualize a given wave for exactly N seconds. You do not need to worry about...
Give a step by step description of the physics and mathematics needed to calculate the trajectory...
Give a step by step description of the physics and mathematics needed to calculate the trajectory of a water bottle rocket in three dimensions. In addition, if the location of the landing of a water bottle rocket could be controlled, what is the physics and mathematics needed to establish control? Consider the question in three dimensions.
Give a step by step description of the physics and mathematics needed to calculate the trajectory...
Give a step by step description of the physics and mathematics needed to calculate the trajectory of a water bottle rocket. In addition, if the location of the landing of a water bottle rocket could be controlled, what is the physics and mathematics needed to establish control?
explain how microscopy technique in biological experiments relates to physics and mathematics
explain how microscopy technique in biological experiments relates to physics and mathematics
Discuss the lack of diversity in economics and other STEM fields, such as mathematics. How can...
Discuss the lack of diversity in economics and other STEM fields, such as mathematics. How can we increase the presence of minorities in quantitative fields?
Discrete Mathematics: Choose the correct choices. There could be more than one answer: Events A and...
Discrete Mathematics: Choose the correct choices. There could be more than one answer: Events A and B are independent events if(choose all correct answers). Note: P(A) denotes probability of event A. a) P(A intersection symbol B)=P(A|B)P(B) b) P( A intersection symbol B)=P(A)P(B) c) P( A intersection symbol B)=P( B intersection symbol A) d) P(A|B)=P(B|A)
- Where receptive fields are small, they are served by more OR fewer (choose one) receptors...
- Where receptive fields are small, they are served by more OR fewer (choose one) receptors in that region. Where receptive fields are small, you are more OR less (choose one) sensitive? - Which of the following is NOT one of the steps of sensory processing? Choose one a. transduction of the signal b. transmission of the signal to the integrating center c. perception of the stimulus at the integrating center d. motor response to the signal Thank you so...
Living things are constrained by the laws of physics, chemistry, and mathematics. Provide two examples of...
Living things are constrained by the laws of physics, chemistry, and mathematics. Provide two examples of physical laws. - For each example explicitly name the law to explain what physiological processes are described by the law using specific examples. - explain why the limits of the laws constrain the function of animal bodies - - what does the law limit for each example?
True/False Mathematics is used in physics mainly to impress people. Most of the world uses the...
True/False Mathematics is used in physics mainly to impress people. Most of the world uses the US Customary System of units. A rocket doesn’t need a surrounding medium to push against in order to move. The kilogram is a unit of mass. Acceleration is a vector.
There are 18 books on a shelf: 6 mathematics, 4 physics, 5 history, and 3 biology....
There are 18 books on a shelf: 6 mathematics, 4 physics, 5 history, and 3 biology. If Emil picks six books at random, what is the probability that he picks 3 mathematics,  2 physics and one other book?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT