Subject Computer Science C-Family Programming

Question

1.Graph is a very important data structure in computer science. It is used in many useful problems (e.g., Google maps). You can find the details of graphs here. In this problem, you will write C++ code to implement a simple graph using the following classes:
i.A class called Vertex that has the following: i. A private member called "value" of type char
ii. A default public constructor which sets value to NULL.
iii. Another public constructor that takes a character c as input and sets value to c.
iv. A public function "void printVertex( )" that just prints the character (value).

II.A class called Edge that has the following:
i. A private variable called "weight" of type int.
ii. Two private variables called "start" and "end", each of type Vertex.
iii. A default public constructor that sets "start" and "end" to a vertex created using its default constructor.
iv. Another public constructor that takes two vertices "s" "e" and another int "w" as input that sets "start" to "s", "end" to "e" and weight to "w".
v. A public function called "void printEdge( )" that calls start's printVertex( ), end's printVertex( ) functions and also prints the edge's weight.

III.Another class called "Graph" with the following data and functions:
i. A private variable called "count" of type int that keeps track of the number of edges.
ii. Another private variable called "allEdges" that is an array of edges (Edge[MAXNUM], where MAXNUM is some predefined number).
iii. A default public constructor that sets count to 0.
iv. A public function called "void addEdge(Edge e)" that adds an edge "e" to the graph. It should simply add e to the array of edges of the graph (allEdges) and increment count.
v. A public function called "printGraph( )" that prints all the edges by calling "printEdge( )" of each edge of the graph.

IV. In the main function do the following:
i. Create at least 6 vertices.
ii. Using the vertices, create at least 5 edges.
iii. Define a graph using its default constructor.
iv. And add each of the edges to the graph.
v. Call the printGraph( ) function of the graph.

--------------------------------------------------------------------------------
2. Define an array of integers of at least 10 elements. initialize it with any meaningful values. Without sorting the array in any way, find the third largest element of the array.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include "Vertex.h"
#include <iostream>

using namespace std;

Vertex::~Vertex()
{
}

void Vertex::printVertex()
{
cout << value;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Checkers Game Using Socket Communication
Homework Solution
$40.00
Programming
Computer Science
Checkers Game
Moves
Players
Codes
Rules
Statements
Variables
Functions
Socket Communication
Managers
Threads
Parent Process
Child Process
Results
Winners
Superhero Fight in C++
Homework Solution
$35.00
Programming
Classes
Vectors
Operators
Pointers
Computer Science
Superhero Fight
Game Developments
C++
OOP
Powers
Drivers
Lasers
Strength
Variables
Loops
Statements
Interfaces
Strings
Integers
Random Functions
Input
Output
Programming Questions
Homework Solution
$20.00
Programming
C++
Computer Science
Integers
Series
Savings Accounts
Balance
Loops
Statements
Variables
Interest Rates
Deposits
Withdrawals
Input
Output
Number Conversion to Any Base
Homework Solution
$18.00
Base Conversion
Hexadecimal
Any Base
Convert
Number
Computer Science
C-Family Programming
Get help from a qualified tutor
Live Chats