1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Illusion [34]
3 years ago
9

Write a program that prints the day number of the year, given the date in the form month-day-year. For example, if the input is

1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4, but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400.
Computers and Technology
1 answer:
vlabodo [156]3 years ago
4 0

Answer:

C++:

C++ Code:

#include <iostream>

#include <string>

using namespace std;

struct date

{

  int d,m,y;

};

int isLeap(int y)

{

  if(y%100==0)

  {

      if(y%400==0)

      return 1;

      return 0;

  }

  if(y%4==0)

  return 1;

  return 0;

}

int day_no(date D)

{

  int m = D.m;

  int y = D.y;

  int d = D.d;

  int i;

  int mn[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

  for(i=0;i<m;i++)

  {

      d += mn[i];

  }

  if(isLeap(y))

  {

      if(m>2)

      d++;

  }

  return d;

}

date get_info(string s)

{

  date D;

  int i,p1,p2,l = s.length();

  for(i=0;i<l;i++)

  {

      if(s[i] == '-')

      {

      p1 = i;

      break ;

      }

  }

  for(i=p1+1;i<l;i++)

  {

      if(s[i] == '-')

      {

      p2 = i;

      break ;

      }

  }

 

  D.m = 0;

  for(i=0;i<p1;i++)

  D.m = (D.m)*10 + (s[i]-'0');

 

  D.d = 0;

  for(i=p1+1;i<p2;i++)

  D.d = (D.d)*10 + (s[i]-'0');

 

  D.y = 0;

  for(i=p2+1;i<l;i++)

  D.y = (D.y)*10 + (s[i]-'0');

 

  return D;

 

}

int main()

{

  string s1 = "4-5-2008";

  string s2 = "12-30-1995";

  string s3 = "6-21-2000";

  string s4 = "1-31-1500";

  string s5 = "7-19-1983";

  string s6 = "2-29-1976";

 

  cout<<"Date\t\tDay no\n\n";

  cout<<s1<<"\t"<<day_no(get_info(s1))<<endl;

  cout<<s2<<"\t"<<day_no(get_info(s2))<<endl;

  cout<<s3<<"\t"<<day_no(get_info(s3))<<endl;

  cout<<s4<<"\t"<<day_no(get_info(s4))<<endl;

  cout<<s5<<"\t"<<day_no(get_info(s5))<<endl;

  cout<<s6<<"\t"<<day_no(get_info(s6))<<endl;

 

 

  return 0;

}

Explanation:

You might be interested in
We write programs as a sequence of operation. they flow through the computer as?
lys-0071 [83]
I belive the correct answer would be binary code because computers see the coding as 00100001 
5 0
3 years ago
I WILL MARK BRAINLIEST IF CORRECT!!!!!!!!!!!!!!!!!!!!!!!!!!!!
e-lub [12.9K]

the second answer is correct

7 0
3 years ago
Read 2 more answers
Substances become a form of “self-soothing” when one feels_______. a) stressed b) anxious c) the need for a reward d) all of the
Fynjy0 [20]
The answer vshould be stressed
3 0
3 years ago
Read 2 more answers
Algorithm to calculate the area of a circle where radius is 7cm.​
zvonat [6]

Answer:

area of a circle =

\pi \times r \times r

22/7 x 7 x 7

22 x 7

54

7 0
3 years ago
Use a loop with indirect or indexed addressing to reverse the elements of the integer array in place. Do not copy the elements t
finlep [7]

Answer:

INCLUDE Irvine32.inc

.data

      ;declare and initialize an array

      array1 DWORD 10d,20d,30d,40d,50d,60d,70d,80d,90d

.code

main PROC

      ;assign esi value as 0

      mov esi,0

      ;find the size of array

      mov edi, (SIZEOF array1-TYPE array1)

      ;find the length of the array

      ;divide the length by 2 and assign to ecx

      mov ecx, LENGTHOF array1/2

;iterate a loop to reverse the array elements

L1:

      ;move the value of array at esi

      mov eax, array1[esi]

      ;exchange the values eax and value of array at edi

      xchg eax, array1[edi]

      ;move the eax value into the array at esi

      mov array1[esi], eax

      ;increment the value of esi

      add esi, TYPE array1

      ;decrement the value of edi

      sub edi, TYPE array1

      loop L1

;The below code is used to print

;the values of array after reversed.

      ;get the length of the array

      mov ecx, LENGTHOF array1

      ;get the address

      mov esi, OFFSET array1

L2:

      mov eax, [esi]

      ;print the value use either WriteDec or DumpMems

      ;call WriteDec

      ;call crlf

      call DumpMem

      ;increment the esi value

      add esi, TYPE array1

      LOOP L2

exit

main ENDP

END main

4 0
3 years ago
Other questions:
  • Behaving in an acceptable manner within a workplace environment is referred to as having
    9·1 answer
  • What will be displayed as a result of executing the following code?
    5·1 answer
  • When an attacker promotes themselves as reputable third-party advertisers to distribute their malware through the Web ads,
    15·1 answer
  • A printer is connected locally on Computer1 and is shared on the network. Computer2 installs the shared printer and connects to
    10·1 answer
  • Q: If a program is invoked with "python program.py -r input.dat output.dat", what are the elements of argv?
    10·1 answer
  • Write a program that (a) generates a vector with 20 random integer elements with integers between -29 and 30, (b) replaces all t
    13·1 answer
  • HELP PLX ITS PYTHON BTW!!!
    8·1 answer
  • MyProgramming Lab
    5·1 answer
  • Create One print command in LOGO​
    12·1 answer
  • Write l for law of enrtia,ll for law of Acceleration and lll for law of enteraction.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!