Small memory size in context

#include <iostream> #include <vector> #include <string> #include <map> using namespace std; struct memory_chip { string model; string manufacturer; float size_kbit; float price_usd; float size_bytes; }; class Student { private: int id; string name; string university_name; double semeter_fee; float travel_time; map<string, float> exams_notes; public: Student(int ID, string n, string un, double sf, float tt, const map<string, float>& en) { id = ID; name = n; university_name = un; semeter_fee = sf; travel_time = tt; exams_notes = en; }; string get_name() { return name; }; string get_university_name() { return university_name; }; double get_semester_fee() { return semeter_fee; }; float get_travel_time() { return travel_time; }; map<string, float> get_exams_notes() { return exams_notes; }; }; template<typename Type> float count_items(memory_chip chip, Type item_bytes) { return chip.size_bytes / sizeof(item_bytes); }; float count_string_items(memory_chip chip, string str) { return chip.size_bytes / (float) (str.size()); }; template<typename Type> float count_array_items(memory_chip chip, Type *arr, int arr_len) { return chip.size_bytes / (sizeof(arr) + (sizeof(Type) * arr_len)); }; template<typename Type> float count_vector_items(memory_chip chip, const vector<Type>& v) { return chip.size_bytes / (sizeof(vector<Type>) + (sizeof(Type) * v.size())); }; int main() { Student s(1, "Peter Tenderson", "University of Oklahoma", 2400.5, 35.2, {{"Software ergonimics", 3.0}, {"Economics", 2.5}, {"Analysis 1", 1.7}, {"Software archtecture", 4.0}, {"Computer vision", 5.0}, {"Graphic design", 2.4}}); bool boolean = true; string word = "abcdefgh"; string sentence = "As he crossed toward the pharmacy at the corner he involuntarily turned his head because of a burst of light that had ricocheted from his temple, and saw, with that quick smile with which we greet a rainbow or a rose, a blindingly white parallelogram of sky being unloaded from the van—a dresser with mirrors across which, as across a cinema screen, passed a flawlessly clear reflection of boughs sliding and swaying not arboreally, but with a human vacillation, produced by the nature of those who were carrying this sky, these boughs, this gliding façade."; int integer = 4; float float_num = 12886768.0f; double double_num = 123123.0; string array_of_strings[] = {"As", "he", "crossed", "toward", "the", "pharmacy", "at", "the", "corner", "he", "involuntarily", "turned", "his", "head", "because", "of", "a", "burst", "of", "light", "that", "had", "ricocheted", "from", "his", "temple,", "and", "saw,", "with", "that", "quick", "smile", "with", "which", "we", "greet", "a", "rainbow", "or", "a", "rose,", "a", "blindingly", "white", "parallelogram", "of", "sky", "being", "unloaded", "from", "the", "van—a", "dresser", "with", "mirrors", "across", "which,", "as", "across", "a", "cinema", "screen,", "passed", "a", "flawlessly", "clear", "reflection", "of", "boughs", "sliding", "and", "swaying", "not", "arboreally,", "but", "with", "a", "human", "vacillation,", "produced", "by", "the", "nature", "of", "those", "who", "were", "carrying", "this", "sky,", "these", "boughs,", "this", "gliding", "façade."}; int array_of_integers[] = {1,2,3,4,5,6,7,8,9,0}; size_t strings_in_array = sizeof(array_of_strings) / sizeof(array_of_strings[0]); size_t integers_in_array = sizeof(array_of_integers) / sizeof(array_of_integers[0]); vector<string> vector_of_strings = {"As", "he", "crossed", "toward", "the", "pharmacy", "at", "the", "corner", "he", "involuntarily", "turned", "his", "head", "because", "of", "a", "burst", "of", "light", "that", "had", "ricocheted", "from", "his", "temple,", "and", "saw,", "with", "that", "quick", "smile", "with", "which", "we", "greet", "a", "rainbow", "or", "a", "rose,", "a", "blindingly", "white", "parallelogram", "of", "sky", "being", "unloaded", "from", "the", "van—a", "dresser", "with", "mirrors", "across", "which,", "as", "across", "a", "cinema", "screen,", "passed", "a", "flawlessly", "clear", "reflection", "of", "boughs", "sliding", "and", "swaying", "not", "arboreally,", "but", "with", "a", "human", "vacillation,", "produced", "by", "the", "nature", "of", "those", "who", "were", "carrying", "this", "sky,", "these", "boughs,", "this", "gliding", "façade."}; vector<int> vector_of_integers = {1,2,3,4,5,6,7,8,9,0}; memory_chip chip{"PCA24S08ADP,118", "NXP", 8, 0.56}; float size_kB = chip.size_kbit / 8; chip.size_bytes = size_kB * 1024; cout << "The " << size_kB << "kB chip " << chip.model << " by " << chip.manufacturer << " could potentially store: " << endl << count_items(chip, s) << " student objects or " << endl << count_items(chip, boolean) << " boolean flags or" << endl << count_string_items(chip, word) << " words of eight characters or" << endl << count_string_items(chip, sentence) << " long sentences or" << endl << count_items(chip, integer) << " integers or" << endl << count_items(chip, float_num) << " floats or" << endl << count_items(chip, double_num) << " doubles or" << endl << count_array_items(chip, array_of_strings, strings_in_array) << " arrays of strings or" << endl << count_array_items(chip, array_of_integers, integers_in_array) << " arrays of ten integers or" << endl << count_vector_items(chip, vector_of_strings) << " vectors of strings or" << endl << count_vector_items(chip, vector_of_integers) << " vectors of ten integers" << endl; return 0; } /* The 1kB chip PCA24S08ADP,118 by NXP could potentially store: 7.52941 student objects or 1024 boolean flags or 128 words of eight characters or 1.82857 long sentences or 256 integers or 256 floats or 128 doubles or 0.335958 arrays of strings or 21.3333 arrays of ten integers or 0.334204 vectors of strings or 16 vectors of ten integers */