1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Studentka2010 [4]
3 years ago
6

Design and implement a class Country that stores the name of the country, its population, its area, and the population density (

i.e., people per square kilometer (or mile). In other words, there are four major methods in this class (i.e., get country name, get area information, get population information, and get population density information). Then, write a test file that reads data.txt and prints the following three tasks by leveraging methods from the Country() class.  The country with the largest area. The country with the largest population.  The country with the largest population density You should turn in TWO Python files in this question. One is a Country class file and the other is the test program that leverages the methods from the Country()class and print the above three requests. You could leverage set() to store country information and do the operations.

Computers and Technology
1 answer:
melomori [17]3 years ago
4 0

Answer:

See explaination

Explanation:

Make use of Python programming language.

File: Country.py

class Country:

def __init__(self, n="", p=0, a=0):

""" Constructor """

self.name = n

self.population = p

self.area = a

self.pDensity = self.population / self.area

def getCountryName(self):

""" Getter method """

return self.name

def getPopulation(self):

""" Getter Method """

return self.population

def getArea(self):

""" Getter Method """

return self.area

def getPDensity(self):

""" Getter Method """

return self.pDensity

File: CountryInfo.py

from Country import *

# Opening file for reading

with open("d:\\Python\\data.txt", "r") as fp:

# List that hold countries

countryInfo = []

# Processing file line by line

for line in fp:

# Stripping spaces and new lines

line = line.strip()

# Splitting and creating object

cols = line.split('\t')

cols[1] = cols[1].replace(',', '')

cols[2] = cols[2].replace(',', '')

c = Country(cols[0], int(cols[1]), float(cols[2]))

countryInfo.append(c)

# Processing each countryInfo

largestPop = 0

largestArea = 0

largestPDensity = 0

# Iterating over list

for i in range(len(countryInfo)):

# Checking population

if countryInfo[i].getPopulation() > countryInfo[largestPop].getPopulation():

largestPop = i;

# Checking area

if countryInfo[i].getArea() > countryInfo[largestPop].getArea():

largestArea = i;

# Checking population density

if countryInfo[i].getPDensity() > countryInfo[largestPop].getPDensity():

largestPDensity = i;

print("\nLargest population: " + countryInfo[largestPop].getCountryName())

print("\nLargest area: " + countryInfo[largestArea].getCountryName())

print("\nLargest population density: " + countryInfo[largestPDensity].getCountryName() + "\n")

Please go to attachment for sample program run

You might be interested in
The SQL WHERE clause: Limits the row data that are returned. Limits the column data that are returned. ALL Limits the column and
enyata [817]

Answer: Limits the row data that are returned.

Explanation: In structured query language (SQL), The where clause is used as a filter. The filter is applied to a column and as such the filter value or criteria determines the values that are spared in the column on which the WHERE clause is applied. All rows in which the column value does not meet the WHERE clause criteria are exempted from the output. This will hence limit the number of rows which our command displays.

For instance,

FROM * SELECT table_name WHERE username = 'fichoh' ;

The command above filters the username column for username with fichoh, then displays only rows of Data with fichoh as the username. All data columns are displayed but rows of data which do not match fichoh are exempted.

3 0
2 years ago
write a 2d array c program that can capture marks of 15 students and display the maximum mark, the sum and average​
bekas [8.4K]

Answer:

#include <stdio.h>  

int MaxMark(int* arr, int size) {

   int maxMark = 0;

   if (size > 0) {

       maxMark = arr[0];

   }

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

       if (arr[i] > maxMark) {

           maxMark = arr[i];

       }

   }

   return maxMark;

}

int SumMarks(int* arr, int size) {

   int sum = 0;

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

       sum += arr[i];

   }

   return sum;

}

float AvgMark(int* arr, int size) {

   int sum = SumMarks(arr, size);

   return (float)sum / size;

}

int main()

{

   int student0[] = { 7, 5, 6, 9 };

   int student1[] = { 3, 7, 7 };

   int student2[] = { 2, 8, 6, 1, 6 };

   int* marks[] = { student0, student1, student2 };

   int nrMarks[] = { 4, 3, 5 };

   int nrStudents = sizeof(marks) / sizeof(marks[0]);

   for (int student = 0; student < nrStudents; student++) {              

       printf("Student %d: max=%d, sum=%d, avg=%.1f\n",  

           student,

           MaxMark(marks[student], nrMarks[student]),

           SumMarks(marks[student], nrMarks[student]),

           AvgMark(marks[student], nrMarks[student]));

   }

   return 0;

}

Explanation:

Here is an example using a jagged array. Extend it to 15 students yourself. One weak spot is counting the number of marks, you have to keep it in sync with the array size. This is always a problem in C and would better be solved with a more dynamic data structure.

If you need the marks to be float, you can change the types.

3 0
2 years ago
What is the term used for the initial document that includes the necessary information to build a game?
arlik [135]

Game design document is the term used for the initial document that includes the necessary information to build a game

Explanation:

A game design document serves as a nexus and core to combine and list all features of a game. It consists of written descriptions, images, graphs, charts and lists of data relevant to specific parts of improvement, and is usually formed by what characteristics will be in the game, and sets out how they will all fit together.

Creating a GDD will assist the team's designer in knowing what the fragrance of the game is and the intended range of its overarching world. Holding all the game factors in one well-organized document will help the designer easily communicate their idea to the rest of the team, and also healing to pinpoint deficiencies or missing components of the game. The GDD should serve as your master checklist.

4 0
2 years ago
I don't understand how to write both. If I repeat the first code but with 3 and 6 it doesn't work.
hram777 [196]

It looks like you need to get both numbers from the input. Try doing something like this:

print(int(input()) + int(input()))

4 0
2 years ago
What best describes the difference between plagiarism and fair use
Colt1911 [192]
The answer is ..........
 
<span>Fair use </span>

The doctrine of fair use allows the limited use of copyrighted material for certain educational, scholarly and research purposes without the permission of the copyright owner. It applies to any copyrighted material regardless of source, including the Internet. If you photocopy a page from one of your textbooks or print a page from a copyrighted Internet site for certain educational, scholarly or research purposes, your actions may fall under the doctrine of fair use. The copyright laws give you permission to copy the work<span> (with certain limitations), even though the owner of the copyright did not.


V.S

</span>Plagiarism

Plagiarism is "the representation of another's work or ideas as one's own; it includes the unacknowledged word-for-word use and/or paraphrasing of another<span> person's work, and/or the inappropriate unacknowledged use of another person's </span><span>ideas" (The Ohio State University Code of Student Conduct). This means that if </span><span>you use another person's work when completing any academic assignment,</span><span> </span><span>regardless </span>

5 0
3 years ago
Read 2 more answers
Other questions:
  • Describe the indicators and hazards of a metal deck roof fire in an unprotected steel joist warehouse as well as the techniques
    6·1 answer
  • one business rule is that each project has one manager. Identify two (and no more than two) problems with the data structure or
    9·1 answer
  • A database interrogation is a major benefit of the database management approach, where end users can query (“ask”) the database
    6·1 answer
  • A hacker scanning a web server is likely to be identified by the target's web a. Because of the FBI's Carnivore scanning program
    12·1 answer
  • How do you change colors for presentation to blue warm in power point?
    11·1 answer
  • How can a smartphone's gyroscope and accelerometer be used in product marketing? A. to locate the user's geographical position B
    5·1 answer
  • In PKI, the CA periodically distributes a(n) _________ to all users that identifies all revoked certificates.
    13·1 answer
  • Qwertyuiopasdfghjklzxcvbnm??
    14·2 answers
  • Which of the following is true about named ranges?
    6·1 answer
  • Which display technology was developed by apple, produces vibrant colors, and supports viewing from all angles?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!