0% found this document useful (0 votes)
2 views2 pages

Coding

This C++ program collects space debris data from four countries: USA, China, India, and UK. It calculates the maximum debris value and generates a simple bar graph representation of the debris data for each country. The output displays the country names alongside a visual representation of the debris amounts using bars.

Uploaded by

kthamayanthi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Coding

This C++ program collects space debris data from four countries: USA, China, India, and UK. It calculates the maximum debris value and generates a simple bar graph representation of the debris data for each country. The output displays the country names alongside a visual representation of the debris amounts using bars.

Uploaded by

kthamayanthi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <vector>

using namespace std;

int main() {

// Get user input for debris data

int usa_debris, china_debris, india_debris, uk_debris;

cout << "Enter space debris data for USA: ";

cin >> usa_debris;

cout << "Enter space debris data for China: ";

cin >> china_debris;

cout << "Enter space debris data for India: ";

cin >> india_debris;

cout << "Enter space debris data for UK: ";

cin >> uk_debris;

// Create a vector to store debris data

vector<int> debris_data = {usa_debris, china_debris, india_debris, uk_debris};

// Create a vector to store country names

vector<string> countries = {"USA", "China", "India", "UK"};

// Find the maximum debris value

int max_debris = debris_data[0];

for (int i = 1; i < debris_data.size(); ++i) {

if (debris_data[i] > max_debris) {

max_debris = debris_data[i];

}
// Print the graph

cout << "\nSpace Debris by Country\n";

for (int i = 0; i < debris_data.size(); ++i) {

// Calculate the number of bars to print

int num_bars = (int)(debris_data[i] / (double)max_debris * 50);

cout << countries[i] << ": ";

for (int j = 0; j < num_bars; ++j) {

cout << "█";

cout << " (" << debris_data[i] << ")\n";

return 0;

You might also like