Question

5. Numerical Integration (15 marks] When a charged particle moves perpendicular to a magnetic field it traces out circles in

Question 5: Numerical Integration (A) t у Vx Vy k1x k1 х 0 0 1 0 0.1 0.2 (B) у VX K1X kly K1X kly x1 y1 VX1 0 0 0 1 0.1 0.2 (

Q3: Write a CH program that creates a simple calculator using switch statement. It reads two float numbers F1, F2 and a chara

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans 3:

#include <iostream>
using namespace std;

int main() {

// Variables to hold operands
float f1, f2;

// Variable to hold operator
   char op;

   // Requesting user to input operands
   cout << "\nEnter a number: ";
   cin >> f1;
   cout << "Enter another number: ";
   cin >> f2;

   // Requesting user to input operator
   cout << "\nEnter a operator: ";
   cin >> op;
   cout << "\n";

   switch(op)
   {
   case '+':
   cout << f1 << " + " << f2 << " = " << f1 + f2;
   break;

   case '-':
   cout << f1 << " - " << f2 << " = " << f1 - f2;
   break;

   case '/':
   cout << f1 << " / " << f2 << " = " << f1 / f2;
   break;

   case '*':
   cout << f1 << " * " << f2 << " = " << f1 * f2;
   break;

default:
cout << "Invalid Operator!";
   }

   return 0;
}

/*********** Output ****************/

Ans 4:

#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;

int main()
{
srand(time(0));
cout << "\nRandom No generated (0.. 100): " << rand() % 101;

return 0;
}

/*************** below is the output *******************/

/********* Note: if you are using -std=c++11 (c++ 11) then you don't need to include stdlib.h *************/

/********** I have included stdlib.h, to just show how it will work in other versions of c++ ***********/

/************ srand(time(0)) seeds the random number generator with current system time, if you don't do this, everytime the code runs you will get the same random number ****************/

/*********** if you have any questions, you may ask in comments *****************/

/**************** thanks for reading ******************/

Add a comment
Know the answer?
Add Answer to:
5. Numerical Integration (15 marks] When a charged particle moves perpendicular to a magnetic field it...
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
ADVERTISEMENT