Find these from the Question Contract Purpose Statement Exam
Find these from the Question:
Contract:
Purpose Statement:
Examples:
Algorithm:
Program:
Functionality:
Code Formatting:
Sample Run (user input in color):
run:
First charge [Coulomb]: 50
Second charge [Coulomb]: 60
Distance [meters]: 5
Force: 1.078529092558586E12
BUILD SUCCESSFUL (total time: 15 seconds)
Solution
#include <iostream>
#include <cmath>
double force(double Q1, double Q2, double Distance){
static const double pi = std::acos(-1);
static const double epsilon = 8.854e-12;
static const double K = 1/(4*pi*epsilon);
return ((K*Q1*Q2)/(Distance*Distance));
}
int main(){
double Q1, Q2, r;
std::cout << \"Q1=\",
std::cin >> Q1;
std::cout << \"Q2=\";
std::cin >> Q2;
std::cout << \"r=\";
std::cin >> r;
std::cout << \"\ Force=\" << force(Q1, Q2, r);
}
