NPTEL » An Introduction to Programming Through C++
Programming Assignment 5.1
Due on 2022-03-03, 23:59 IST
Write a function that takes a number b, and a number N, and returns true/false indicating whether N is a power of b, ie bk=N for some non negative integer k. The function returns true if N can be expressed as a power of b, and false otherwise.
Use the following function signature :
bool isPower(int b,int N).
The following code will be there, but won’t appear in your editor :
main_program{
int b,N;
cin>>b>>N;
if(isPower(b,N))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
This invisible code will test your function. This code will read the values b and N from the test case and print out “Yes” if your function returns true and “No” otherwise.
You don’t need to write/copy the main program. You just need to write the isPower function, without the main_program or any of the header files.
You don’t need to write/copy the main program. You just need to write the isPower function, without the main_program or any of the header files.
Note : Ensure that the name of the function is isPower and it takes the two parameters and returns true or false without printing anything.
Explanation of Sample Testcase 1
Input : b=2, N=1024
Output : 1024 can be expressed as 210. So the function returns true and Yes gets printed out by
the invisible code.
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Programming Assignment 5.2
Due on 2022-03-03, 23:59 IST
Write a void function that takes two value parameters : a and b, and two reference parameters :
q and r. It performs the integer division of a by b, and stores the quotient in q and the remainder in r. All the values : a, b, q and r can be stored in the int data type.
Use the following function signature :
void div(int a, int b, int &q, int &r).
The following code will be there, but won’t appear in your editor :
main_program{
int a,b,q,r;
cin>>a>>b;
div(a,b,q,r);
cout<<q<<" "<<r<<endl;
}
This invisible code will test your function. This code will read the values a and b from the test case, call your div function and will print out the modified values of q and r.
You don’t need to write/copy the main program. You just need to write the div function, without the main_program or any of the header files.
Note : Ensure that the name of the function is div, and it takes the four parameters and stores the quotient and remainder of the division a/b in q and r without printing anything.
Explanation of Sample Testcase 1
Input : a=30, b=7
Output : 30/7 gives 4 as the quotient and 2 as the remainder. After the function returns, q contains 4 and r contains 2
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
See the Quiz Assignment Answers with proof and programs passing test cases.
Please subscribe to our YouTube Channel : Swayam Solver
This will help the creator to continue making quality content...
Have a great day !
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.