Question

In: Computer Science

This assignment requires you to use at least one loop and an array. You can refer...

This assignment requires you to use at least one loop and an array. You can refer to our book and any programs you have written so far. Make sure that your work is your own. Write a comment at the beginning of your program with your name and your birthday (month and day, does not need to include year). For example: John Doe, May 23. Create an array that will store whole numbers. The size of the array should be ten more than the month number of your birthday. Continuing the example, for a birthday in May, the array will be of size 15 since May is the fifth month and 5 + 10 = 15. Then let the user enter each value to store in the array. Perform input validation that the user enters numbers between 1 and the day of the month that is your birthday. (That is, a value is invalid if is less than 1. Similarly, a value is invalid if it is greater than the day of the month that is your birthday.) Continuing the example, for a birthday on the 23 of the month, the valid values the user can enter are 1 through 23. Go through the array and collapse the array into a single representative number as follows: i. First replace every three adjacent integers with the sum of the two numbers. For example, if the first three elements of the array are 1, 2, and 3, they become the single value of 6. For example [1, 2, 8, 9, 4, 13, 7, 1, 9, 10, 5] becomes [11, 26, 17, 15] ii. Go through the new array and modify any number that is larger than 12 to be the difference between it and 12. (You can use either subtraction or modulus for this.) Continuing the example, [11, 26, 17, 15] becomes [11, 14, 5, 3] Then iteratively continue collapsing the array until you have a single representative integer. Continuing the example: Add adjacent three integers in [11, 14, 5, 3] to get [30, 3] Then change it to become [18, 3] Add adjacent three integers in [18, 3] to get the single value of 21 which is modified to be 9 and the result is displayed to the user

Solutions

Expert Solution

//Deepesh Malhotra, Jan 31

//This code is in C++ Language...
#include<bits/stdc++.h>
using namespace std;

int main()
{
   //as my month number is 1 so array size will be month number +10, hence 1+10=11
   int arr[11];
  
   //so user can enter 11 numbers in the arr
   int n,k=0;
   cin>>n;
  
   //checking if n is <= 11 then only we can go further otherwise it will out of range of arr
   if(n<=11)
   {
       //taking values from the user
       for(int i=0;i<n;i++)
       cin>>a[i];
      
       // this loop will give us values which are invaid as values ranges from 1 to 31
       for(int i=0;i<n;i++)
       {
           if(a[i] < 1 || a[i] >31)
           cout<<a[i]<<"Invalid number: Should be greater than 1 and less than 31";
       }
      
       //replacing every 3 adjacent elements of array with their sum
       while(n>=1)
       {
           //as k value will get changed below so we have to make it zero everytime
           k=0;
           for(int i=0;i<n;i=i+3)
           {
               sum=a[i] + a[i+1] + a[i+2];
               a[k]=sum;
               k++;
           }
      
           //updating value of n
           n=k-1;
      
           //if any number is larger than 12 then replace it with the difference the no. and 12
           for(int i=0;i<=n;i++)
           {
               ifa[i] > 12)
               a[i]=a[i] - 12;
           }
          
       //repeating this process till one single element is left
       }
      
       //printing the result
       cout<<a[0];
}


Related Solutions

This assignment requires you to use at least one loop and an array. You can refer...
This assignment requires you to use at least one loop and an array. You can refer to our book and any programs you have written so far. Make sure that your work is your own. Write a comment at the beginning of your program with your name and your birthday (month and day, does not need to include year). For example: John Doe, May 23 Create an array that will store whole numbers. The size of the array should be...
FINANCE ASSIGNMENT **THIS ASSIGNMENT REQUIRES THE USE OF MICROSOFT EXCEL** Refer to information page on the...
FINANCE ASSIGNMENT **THIS ASSIGNMENT REQUIRES THE USE OF MICROSOFT EXCEL** Refer to information page on the use of some finance features in Excel. Understand financial functions @PMT, @PPMT, @IPMT, @PV and @FV. See here. 1. Assume you are employed at $60,000 per year. Consider such deductions as social security, income taxes (federal, state and county) and your payment on health benefits. Do the best you can to come to grips with what is a realistic monthly take home pay. 2....
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for...
USE VISUAL STUDIO/VB In this assignment, you will create an array of ten elements, one for name, one for hours worked,and the last for hourly rate. The arrays will receive the information from inputs from the screen.For example, you will ask the following three questions: a) Employee name: b) Hours worked: c) Hourly rate: After you have received all ten records and have inserted them into the array, you will then calculate the hourly rate times the hours worked to...
Please, write a loop to print odd numbers an array a with pointers backwards. You can...
Please, write a loop to print odd numbers an array a with pointers backwards. You can use a variable “size” for array size.
this assignment requires you to interview one person and requires an analysis of your interview experience....
this assignment requires you to interview one person and requires an analysis of your interview experience. Part I: Interview Select a patient, a family member, or a friend to interview. Be sure to focus on the interviewee's experience as a patient, regardless of whom you choose to interview. Review The Joint Commission resource which provides some guidelines for creating spiritual assessment tools for evaluating the spiritual needs of patients. Using this resource and any other guidelines/examples that you can find,...
The presentation slides This assignment requires you to look at one interface for a product of...
The presentation slides This assignment requires you to look at one interface for a product of your choice, identify what it was developed for, and then trace back its history (to the origin if possible) to look for similar solutions. This way you'll be clearer what the original problem is and how human through out history has managed it. You'll see that whole or part of the very early solutions seem to stay in most of the newer solutions, and...
In C++, Create an array of 10 characters. Use a loop to prompt for 10 letters...
In C++, Create an array of 10 characters. Use a loop to prompt for 10 letters (a-z|A-Z) and store each in the array. If an invalid character is entered, re-prompt until a valid char is entered. After 10 characters are stored in the array, use a loop to print out all characters in the array from the first to the last element. Then, use another loop starting at the last element to print all characters in the array in reverse...
This assignment requires you to look at one interface for a product of your choice, identify...
This assignment requires you to look at one interface for a product of your choice, identify what it was developed for, and then trace back its history (to the origin if possible) to look for similar solutions. This way you'll be clearer what the original problem is and how human through out history has managed it. You'll see that whole or part of the very early solutions seem to stay in most of the newer solutions, and you'll be able...
1. Define "critical thinking" and briefly provide at least one example of you can use it...
1. Define "critical thinking" and briefly provide at least one example of you can use it outside of class. 2. Read Boss' discussion of "The Three-Tier Model of Thinking" and apply that analogy to an experience in your life. In effect, you will critically analyze an event/experience in your life.
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes. THANKS
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT