Professional Documents
Culture Documents
(i,j) is 1 if there is an edge from vertex i to vertex j; otherwise the entry is 0. A weighted graph
may be represented using the weight as the entry. An undirected graph may be represented
using the same entry in both (i,j) and (j,i) or using an upper triangular matrix.
#include <list>
#include <vector>
private:
bool** adjacencyMatrix;
int vertexCount;
void addEdge(int i, int j) {
if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) {
adjacencyMatrix[i][j] = true;
adjacencyMatrix[j][i] = true;
}
}
void removeEdge(int i, int j) {
if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount) {
adjacencyMatrix[i][j] = false;
adjacencyMatrix[j][i] = false;
}
}
bool isEdge(int i, int j) {
if (i >= 0 && i < vertexCount && j > 0 && j < vertexCount)
return adjacencyMatrix[i][j];
else
return false;
}
~Graph() {
for (int i = 0; i < vertexCount; i++)
delete[] adjacencyMatrix[i];
delete[] adjacencyMatrix;
}
};
2) Total sum=1.0
1.0
/ \
0.60 0.40
/ \ / \
0.30 0.30 0.20 0.20
/ \
0.0.5 0.15
Codes
Int 00
Main 01
While 110
If 11
For 111
3)Public: A member (either data member or member function) declared in a private section of a
class can only be accessed by member functions and friends of that class
Private:A member (either data member or member function) declared in a protected section of a class
can only be accessed by member functions and friends of that class, and by member functions and
friends of derived classes
Protected:A member (either data member or member function) declared in a public section of a
class can be accessed by anyone
#include <iostream>
using namespace std;
class Enemy
{
public:
Enemy(): m_Damage(10) {}
void Attack() const
{ cout << "Attack inflicts " << m_Damage << " damage points!\n"; }
protected:
int m_Damage;
};
class Boss : public Enemy
{
public:
Boss(): m_DamageMultiplier(3) {}
void SpecialAttack() const
{ cout << "Special Attack inflicts " << (m_DamageMultiplier * m_Damage);
cout << " damage points!\n"; }
private:
int m_DamageMultiplier;
};
int main()
{
Enemy enemy1;
enemy1.Attack();
Boss boss1;
boss1.Attack();
boss1.SpecialAttack();
return 0;
}
4)
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str = "Anatoliy";
char *ary = new char[str.length()+1];
ret_str(s+1);
cout<<*(s);
}
}
}