Jump to content
منتدى البحرين اليوم

اسايمنت 8 cs


Recommended Posts

السلام

 

ياخواني و ياخواتي.. أريد أسأل اذا حد يعرف يحل اسايمنت 8 ...

Assignment 8 :

 

Write a program that prompts the user to enter a year and then determines whether it is a leap year. Your program should have a loop and continue while the user enters the character ‘y’.

Write three methods according to the following descriptions:

_ getYear has no formal parameters, asks the user to enter a year, and returns an integer value that is assigned to the integer variable year.

_ isLeap has an integer formal parameter, year, determines whether the year is a leap year, and returns the Boolean value true if the year is a leap year and false if it is not. A year is a leap year if it is divisible by 4, but is not divisible by 100 except when divisible by 400. (The year 2000 was a leap year.)

_ moreData has no formal parameters and returns a char value.

 

Sample Output:

 

This program asks you to enter a year in 4 digits.

The output shows if the year is a leap year

 

Enter a year: 1492

1492 is a leap year.

 

Do you want to enter more data? y/n y

 

Enter a year: 2000

2000 is a leap year.

 

Do you want to enter more data? y/n y

 

Enter a year: 2005

2005 is not a leap year.

 

Do you want to enter more data? y/n y

 

Enter a year: 1800

1800 is not a leap year.

 

Do you want to enter more data? y/n n

 

Link to comment
Share on other sites

حاولت فيه يطلع لي خمس ارورز

:sad:

صعب الفنكشن شوي

 

شوفو حلي

 

واذا احد عرف له يحطه لنا

:dde1:

#include<iostream>

using namespace std;

int getYear();

bool isleap(int);

char moreData();

void main()

 

{

char moreData;

int Year;

 

cout<<"This program asks you to enter a year in 4 digits."<<endl;

cout<<"The output shows if the year is a leap year"<<endl;

 

do

{

cout<<endl;

Year=getYear();

 

if(isleap(Year))

cout<<Year<<"is a leap year."<<endl<<endl;

else

cout<<Year<<"is not a leap year."<<endl<<endl;

}

moreData=moreData();

 

while

 

(moreData!='n');

 

}

int getYear();

{

int y;

cout<<"Enter a year:";

cin>>y;

 

return y;

}

bool isLeap(int x)

 

{

if(x%4==0&&x%100!=0||x%400==0)

 

return true

else

return false

}

{

char m;

cout<<"Do you want to enter more data? y/n";

cin>>m;

return m;

}

 

Link to comment
Share on other sites

#include<iostream>

using namespace std;

int getYear()

{

int y;

cout<<"Enter a year:";

cin>>y;

 

return y;

}

 

bool isleap(int x)

{

 

if(x%4==0&&x%100!=0||x%400==0)

 

return true;

else

return false;

}

 

char moreData()

{

char m;

cout<<"Do you want to enter more data? y/n ";

cin>>m;

return m;

}

 

void main()

 

{

char md1;

int Year;

 

cout<<"This program asks you to enter a year in 4 digits."<<endl;

cout<<"The output shows if the year is a leap year"<<endl;

 

do

{

cout<<endl;

Year=getYear();

 

if(isleap(Year)==true)

cout<<Year<<"is a leap year."<<endl<<endl;

else

cout<<Year<<"is not a leap year."<<endl<<endl;

 

md1=moreData();

}

 

 

 

while

 

(md1!='n');

 

}

 

هذي ياجماعه حل الاسايمنت سويته عقب ما طلعت روحي :ssm11:

 

تحياااااااااااااااتي :aq11:

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
الرد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...