Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ How would I make a program that displays warning messages if the user inputs

ID: 3850951 • Letter: C

Question

C++ How would I make a program that displays warning messages if the user inputs a coordinate with bad notations? So, to enter the point (3,-4), the user should be able to enter any of: (3,-4), 3,-4), (3,-4, (3 -4), 3,-4, 3 -4), (3 -4, or even 3 -4. Only the first would be quiet, however, the others would generate 1, 2, or even 3 warning/reminder messages about missing notation. The program would still continue even if an error is present to get another coordinate the user inputs. It then calculates both the distance between two points in the 2D Cartesian plane and the midpoint of the line segment those two points define. An examples of how the program would look is shown below.

I know how to do simple programs but I dont know where to start when it comes to this one. I tried to do if/else statements but I'm not very good at branching/looping to make something like this. My professor doesn't lecture very well and I've looked online as to where to start but have a lot of issues and have wasted a lot of time. Can someone help me program this?

As an example, you might have the program interaction look something like (the parts in this color are typed by the user) /pointcalcinp. out Welcome to the 2D Point Program! Where is your first point? 3.4 12.2) You were missing the open parenthesis before the x coordinate You were missing the comma to separate coordinates Please use proper notation... Where is your second point? (13.4 12.2 You were missing the close parenthesis after the y coordinate Please use proper notation... Thank you! Calculating Done. (3. 4, 12.2) is 10 units away from (13.4 12.2) The midpoint of the line segment from (3.4, 12.2) to (13.4 12.2) is (8.4 12.2) Thank you for using the 2PP!! Endeavor to have a day.

Explanation / Answer

#include <iostream>
#include <sstream>
#include <string>
#include <math.h>
#include <string>
//#include <boost/regex.hpp>
double distanceCalculate(double x1, double y1, double x2, double y2)
{
double x = x1 - x2;
double y = y1 - y2;
double dist;

dist = pow(x,2)+pow(y,2);
dist = sqrt(dist);

return dist;
}
void Warning(int level)
{
if(level == 1)
{
std::cout << "You are missing open bracket";
}
if(level == 2)
{
std::cout << "You are missing close bracket";
}
if(level == 3)
{
std::cout << "You are missing comma bracket";
}
if(level == 4)
{
std::cout << "You are missing brackets";
}
if(level == 5)
{
std::cout << "You have entered one value, missing other coordinate";
}

}
int main()
{
std::string point1;
std::string point2;
double x1,y1,x2,y2;
double p1,p2,p3,p4;
char b1,s,b2,b3,s1,b4;
//boost::regex point ("[0-9]+.*[0-9]*")

std::cout << "Enter first point co-ordinate: format(x,y)";
getline(std::cin,point1);
std::cout << "Enter second point co-ordinate:format(x,y)";
getline(std::cin,point2);
std::istringstream iss(point1);
iss >> b1 >> x1 >> s >> y1 >> b2;

if(b1!='(')Warning(1);

f(b2!=')')Warning(5);

f(s!=',')Warning(3);
std::istringstream is(point2);
is >> b3 >> x2 >> s1 >> y2 >> b4;

if(b3!='(')Warning(1);

f(b4!=')')Warning(5);

f(s1!=',')Warning(3);

std::cout << "Distance is ";
std::cout<<distanceCalculate(x1,y1,x2,y2);

}