Question
the language is c++

Goals: Developing problem-solving skills, declaring variables, multi-way branches, data validation. Problem: Astronomers have
Create a program will prompt the user to enter a time in days and calculate the magnitude of the binary star for that time. Y
Goals: Developing problem-solving skills, declaring variables, multi-way branches, data validation. Problem: Astronomers have measured the magnitude (brightness) of a binary star as a function of time and found it to have periodicity (cycle) of 6.4 days. The magnitude varies as given below. from times t 0 days until t 0.9 days the magnitude is 2.5 from times t-0.9 days until t 2.3 days the magnitude may be calculated by the fomula 3.355- In(1.352+cos(x* (t - 0.9)0.7) from times t 2.3 days until t 4.4 days the magnitude is 2.5 from times 4.4days until t-5.2 days the magnitude may be calculated by the formula 3.598- In(1.998+cos(r *( t - 4.4)0.4)) from times-5.2 days until t-6.4 days the magnitude is 2.5 At 6.4 days the cycle begins again as if the time was 0 days. A graph for 2 cycles (12.8) days is given below. 4.4 42 4 3.8 3.6 34 32 3 2.8 26 2.4 8 10 12 14
Create a program will prompt the user to enter a time in days and calculate the magnitude of the binary star for that time. Your program should use a simple if to ensure that the entered time is valid (greater than or equal to 0) and prompt the user to re-enter if the entered time is invalid. Then use an if-elseif structure to determine the magnitude for the entered time. Your output should be similar to Output the days to 3 significant figures days the magnitude of the binary star is 15 "At and the magnitude to 5 significant figures. Hint: The fimod function will calculate the remainder of floating-point division.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
float days,angle,magnitude; //variables for storing number of days, the angle used in cosine and magnitude of brightness
cout<<"Enter the number of days: "; //Prompting the user to enter the number of days
cin>>days; //User entering the number of days
while(days<0.0) //if user enters a negative value
{ //Prompting him to enter the value again
cout<<"Enter a number greater than 0: ";
cin>>days;
}
float days2=fmod(days,6.4); //variable to store days%6.4 as cycle is of 6.4 days
if(days2<0.9) //If days are from 0 to 0.9
{
magnitude=2.5; //then magnitude = 2.5
}
else if(days2<2.3) //If days are from 0.9 to 2.3
{
angle=3.14*(days-0.9); //calculating angle to be used in cosine
angle=angle/0.7;
magnitude=3.355-(log(1.352+cos(angle))); //formula for magnitude
}
else if(days2<4.4) //If days are from 2.3 to 4.4
{
magnitude=2.5; //then magnitude is 2.5
}
else if(days2<5.2) //If days are from 4.4 to 5.2
{
angle=3.14*(days-4.4); //calculating angle to be used in cosine
angle=angle/0.4;
magnitude=3.598-(log(1.998+cos(angle))); //formula for magnitude
}
else //If days are from 5.2 to 6.4
{
magnitude=2.5; //then magnitude is 2.5
}
cout<<"At ";
cout<<setprecision(3)<<days; //setting precision of days to 3
cout<<" days the magnitude of the binary star is ";
cout<<setprecision(5)<<magnitude<<endl; //setting precision of magnitude to 5
return 0;
}

Output

Enter the number of days: -2.3 number greater than 0: 11.2 Enter a At 11.2 days the magnitude of the binary star is 3.5996 .

Add a comment
Know the answer?
Add Answer to:
the language is c++ Goals: Developing problem-solving skills, declaring variables, multi-way branches, data valida...
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
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