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

How does one go about making a program like this? I\'m completely new to c++ and

ID: 3848981 • Letter: H

Question

How does one go about making a program like this? I'm completely new to c++ and can only do simple input/output math programs.

/point calcinp.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

Solution:

#include<iostream>
#include<string>
using namespace std;
int main()
{
   string st,st1;
   string pt1,pt2;
   cout<<" Welcome to the 2D Points Program!!!"<<endl;
   cout<<"Where is your first point?: ";
   cin.ignore();
   getline(cin,st);
   st1=st;
   int flag=0;
   if((st.at(0)!='('))
   {
       cout<<"You were missing open parenthesis before the x coordinate!"<<endl;
       flag=1;
       pt1=st.substr(1,3);
   }
   else
       pt1=st.substr(2,3);
   if((st.at(st.size()-1)!=')'))
   {
       cout<<"You were missing close parenthesis after the y coordinate!"<<endl;
       flag=1;
       pt2=st.substr(st.size()-3,3);
   }
   else
   {
       pt2=st.substr(st.size()-4,3);
   }
   std::size_t found=st.find(',');
   if (found!=std::string::npos)
   {
       cout<<"You are missing comma to seperate coordinates!"<<endl;
       flag=1;
   }
   if(flag==1)
       cout<<"Please use proper notations"<<endl;
   cout<<"Thank you!! Calculating...Done"<<endl;
   cout<<pt1<<pt2<<endl;
   system("pause");
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote