Selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort. Selection sort is noted for its simplicity, and also has performance advantages over more complicated algorithms in certain situations.
Greeting.h: interface for the Greeting class.
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GREETING_H__34246B3E_5382_401E_9265_7B6DFEFA39AF__INCLUDED_)
#define AFX_GREETING_H__34246B3E_5382_401E_9265_7B6DFEFA39AF__INCLUDED_
#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000
class Greeting {public:void PrintMessage();Greeting();virtual ~Greeting();
private:char* message;};
#endif // !defined(AFX_GREETING_H__34246B3E_5382_401E_9265_7B6DFEFA39AF__INCLUDED_)
Select Greeting.cpp file and edit it. Enter a line
message="Hello World!\n";
inside the Greeting class constructor
Greeting::Greeting(){message = "Hello World\n";}
Enter line of code inside the PrintMessage function
printf(message);
void Greeting::PrintMessage(){ printf(message);}
Enter a line #include <> under existing #include lines
#include "stdafx.h"#include "Greeting.h"#include
Your Greeting.cpp file should be like this:
Greeting.cpp: implementation of the Greeting class.
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"#include "Greeting.h"#include
//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////
Greeting::Greeting(){ message = "Hello World\n";}
Greeting::~Greeting(){}
void Greeting::PrintMessage(){ printf(message);}
Select HelloWorld.cpp file and enter the following two line of code in main function.
Greeting gr;gr.PrintMessage();
Now your HelloWorld.cpp file must be like this:
// HelloWorld.cpp : Defines the entry point for the console application.
#include "stdafx.h"#include "Greeting.h"
int main(int argc, char* argv[]){Greeting gr;gr.PrintMessage();return 0;}
No comments:
Post a Comment