c-programming-73

In this chapter we’re getting our first look at Object Oriented Programming (OOP) which refers to the coupling of data and the functions that operate on that data. In all of our programs up to this point, we’ve used some variables and maybe a few structs, but we haven’t written an example where we tightly coupled the a data structure (like bridge traffic) with the functions that operate on it (like updating the bridge traffic for a single bridge, in a single month). OOP is a paradigm of software design that is the foundation of most modern software, especially large programs.

We will not go into OOP in depth in this class, but our study of it begins with objects. In C++ we write object specifications using classes.

Assignment

A starter object file that represents data we would find for a single mobile application in the Google Play Store is here: googlePlayApp-1.cpp. Download this file and load it into your IDE. We will add more fields and data to it in class.

Complete the rest of the implementation of this class, writing set and access methods for each of the fields. For example, if there is a data field called “price”, add and complete two methods in that class: setPrice() and getPrice(). Also be sure to add the ability to set these fields in the constructor.

Here are the other requirements:

1) The number of installs of an app. is handled differently in the Play Store. If an app has over 1,000,000 installs, the number of installs will be displayed as “1M+ Installs”. Add a field numInstalls of data type int. In the access method for this field (getNumInstalls()), return a string instead of an int, and say “1M+ installs” if the number is over 1,000,000, otherwise use the number as-is, converted to a string. You can convert the string the same way we’ve been using for input: string s = atoi(numInstalls.c_str());

2) Price is handled in a similar way — if the price is 0.0, the getPrice() function should return the word ‘Free’, else the price as a string.

3) Write a main() program that creates 3 apps, with names (and other parameters) of your choosing. You can use either 3 variables or an array. One of the apps. should have numInstalls set to over 1M to test your code for #1.

4) Output the 3 apps and all their attributes using the access methods you created.

5) All of the data you add to the file must be private, while the functions should be public.

What to submit in Canvas

Submit your .cpp file as usual, with a screenshot of 1 run of the program.

Example Output

The three apps in the store are:

Name: Name Art Photo Editor
Number of installs: 1M+
Rating: 4.5
Price: Free
Number of reviews: 4294

Name: Easy Origami Ideas
Number of installs: 4939
Rating: 4.0
Price: $1.99
Number of reviews: 122

Name: Minecraft
Number of installs: 1M+
Rating: 4.9
Price: $4.99
Number of reviews: 2376564

I also upload the helping cpp file.