Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
how to implement this

d = squareroot (( x1 - x2)square + (y1 - y2) square)

here are the codes

I am suppose to use inputx and inputy for this formula.






----------------------------------------------------------------------------
C++
#include "MissionPlan.h"
	

using namespace std;

   void MissionPlan::printMainmenu() //Function to print out Main Menu
{  

     "---------------------------------------------------"<<endl<<
     "Welcome to Mission Plan program! \n"<<endl<<
     "1)   Input statistic data"<<endl<<
     "2)   Compute civ index value (for all records)"<<endl<<
     "3)   Print top 5 exploration destinations"<<endl<<
     "4)   Print total distance"<<endl<<
     "5)   Exit"<<endl<<endl<<
     "Plese enter your choice : ";
}

  
void MissionPlan::bubbleSort(PointTwoD array[],const int SIZE)//Bubble sort function for array
{
	int i,j;
	for(i=0;i<size;i++)>
	{
		for(j=0;j<i;j++)>
		{
			if(array[i].getcivIndex()>array[j].getcivIndex())
			{
                                PointTwoD tempPTD;
                                tempPTD.setcivIndex(array[i].getcivIndex());
                                tempPTD.setxy(array[i].getx(),array[i].gety());

				array[i].setcivIndex(array[j].getcivIndex());
				array[j].setcivIndex(tempPTD.getcivIndex());

                                array[i].setxy(array[j].getx(),array[j].gety());
                                array[j].setxy(tempPTD.getx(),tempPTD.gety());
			}

		}

	}

}  

int MissionPlan::main() // switching choices for different output
{
    int choice, inputx, inputy, inputPlanets, inputMoons, entry = 0;
    string inputsunType;
    float inputParticulateDensity, inputPlasmaDensity; 
    const int SIZE = 20;
       
    LocationData newLocationData[SIZE];
    PointTwoD newPointTwoD[SIZE];
    
    printMainmenu();
    
    cin >> choice;
     
    
    while(choice != 999)          
    {
        switch(choice)
        {            
            case 1:  // entry 1
            {                          
                 while(entry<size)>
                 {
                 cout<<"[Input statistical data]"<<endl;
                 cout<<"Please enter x-ordinate : ";
                 cin>>inputx;
                 newPointTwoD[entry].setx(inputx);
                 cout<<"Please enter y-ordinate : ";
                 cin>>inputy;
                 newPointTwoD[entry].sety(inputy);
                 cout<<"Please enter sunType (Type) : ";
                 cin>>inputsunType;
                 newLocationData[entry].setsunType(inputsunType);
                 cout<<"Please enter no of Earth-Like Planets : ";
                 cin>>inputPlanets;
                 newLocationData[entry].setnoOfEarthLikePlanets(inputPlanets);
                 cout<<"Please enter no of Earth-Like Moons : ";
                 cin>>inputMoons;
                 newLocationData[entry].setnoOfEarthLikeMoons(inputMoons);
                 cout<<"Please enter the average particulate density : ";
                 cin>>inputParticulateDensity;
                 newLocationData[entry].setaveParticulateDensity(inputParticulateDensity);
                 cout<<"Please enter the average plasma density : ";
                 cin>>inputPlasmaDensity;
                 newLocationData[entry].setavePlasmaDensity(inputPlasmaDensity); 
                 cout<<endl<<"Record successfully stored. Going back to main menu"<<endl;
                 newPointTwoD[entry].setlocationData(newLocationData[entry]); 
                 ++entry;  
                 printMainmenu();      
                 cin>>choice;
                 break;    
                 };
            }break;
        
         
            case 2 :  //entry 2
            {
                 int x = 0;
                float computeCivIndex[SIZE];
                
                for(int x = 0;x<size;)>
                {           
                    computeCivIndex[x] = newLocationData[x].computeCivIndex(newLocationData[x].getsunType(),newLocationData[x].getnoOfEarthLikePlanets(), newLocationData[x].getnoOfEarthLikeMoons(), newLocationData[x].getaveParticulateDensity(), newLocationData[x].getavePlasmaDensity());
                    newPointTwoD[x].setcivIndex(computeCivIndex[x]);
                    ++x;                   
                }                
         
                    
                cout<<endl<<"Computation completed! ( "<<entry<<" records were updated )"<<endl<<endl<<endl<<endl<<endl;
                printMainmenu();
                cin>>choice;
                
            }break;
            
            case 3 :  //entry 3
            
            {
                
                cout<<endl<<"Total no. of records available = "<<entry<<endl<<
                "Printing top 5 exploration destination"<<endl;
                bubbleSort(newPointTwoD,SIZE);
                for(int x = 0;x<5;++x)
                {
                    
              
                    newPointTwoD[x].toString();
                    
                    
                }
                
                cout<<"Done!"<<endl<<endl<<endl<<endl<<endl;
                printMainmenu();
                cin>>choice;
            }break;

case 4:
Posted
Updated 16-Oct-13 20:49pm
v3
Comments
[no name] 16-Oct-13 22:51pm    
Where is your code? Have you googled this?
Member 10334475 16-Oct-13 23:00pm    
I added it. its supposed to be written in case 4. but I have no idea how to start.
I am using inputx and inputy for the formula.
[no name] 16-Oct-13 23:51pm    
You could start with: Google "calculate sum squares c++".
Captain Price 16-Oct-13 23:26pm    
So you only need an algorithm to calculate this (d = squareroot (( x1 - x2)square + (y1 - y2) square)) expression ?
Member 10334475 17-Oct-13 0:16am    
yes. u are right

1 solution

Your expression is equivalent to C++ statement:

C++
double d = sqrt ((( x1 - x2)*( x1 - x2)) + ((y1 - y2)*(y1 - y2)));


You must include <math.h>, because the function sqrt is used.

Tip: Always use brackets properly in your statements. Most often, not using brackets properly causes undefined behavior.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 17-Oct-13 0:42am    
Include what? Did you look at the text of the answer? Problem escaping < and >..? :-)
—SA
Captain Price 17-Oct-13 2:51am    
Oh ! Hates HTML most of the times. It's math.h and i've fixed it.
Sergey Alexandrovich Kryukov 17-Oct-13 3:06am    
You did it. A 5. :-)
—SA
Captain Price 17-Oct-13 4:14am    
thnks Sergey :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900