Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ practice project , please help i need to study this for the exam. any help appreciated (apparently, im told everything i need is in

C++ practice project, please help i need to study this for the exam. any help appreciated

(apparently, im told everything i need is in the code below)

This is the user_selections.txt

==============

Gremlins_(1984).mkv Scrooged_(1988).mkv Die_Hard_(1988).mkv Gremlins_(1984).mkv Home_Alone_(1990).mkv Elf_(2003).mkv Lethal_Weapon_(1987).mkv Die_Hard_(1988).mkv Bad_Santa_(2003).mkv The_Muppet_Christmas_Carol_(1992).mkv The_Nightmare_Before_Christmas_(1993).mkv Elf_(2003).mkv Gremlins_(1984).mkv Elf_(2003).mkv A_Very_Harold_&_Kumar_3D_Christmas_(2011).mkv Gremlins_(1984).mkv Black_Christmas_(2006).mkv Krampus_(2015).mkv Scrooged_(1988).mkv National_Lampoon's_Christmas_Vacation_(1989).mkv Elf_(2003).mkv Scrooged_(1988).mkv Black_Christmas_(2006).mkv Krampus_(2015).mkv Gremlins_(1984).mkv Scrooged_(1988).mkv Krampus_(2015).mkv Gremlins_(1984).mkv Die_Hard_(1988).mkv Bad_Santa_(2003).mkv

==============

image text in transcribed

This is the ::unit_08_starting_point.cpp

#include

#include

#include

#include

using namespace std;

void fill_array(string, string[], int, string[], int);

void sort_array(string[], int);

bool is_unique(string[], int, int);

void count_votes(string[],int, string[], int[], int);

void print_results(string[], int[], int);

int sum_votes(int[], int);

int win_idx(int[], int);

const int TOT_SELECTIONS = 30;

const int MOVIES = 12;

int main()

{

string selected_choices[TOT_SELECTIONS];

string choices[MOVIES];

int choice_tally[MOVIES];

string selections = "user_selections.txt";

fill_array(selections, selected_choices, TOT_SELECTIONS, choices, MOVIES);

count_votes(selected_choices, TOT_SELECTIONS, choices, choice_tally, MOVIES);

print_results(choices, choice_tally, MOVIES);

cout

system("pause");

return EXIT_SUCCESS;

}

void fill_array(string file,string arr[], int arr_sz,string mov[],int mov_sz)

{ // move txt file into an array

int num = 0;

string name;

ifstream fin;

fin.open(file);

for (int i = 0; i

{

fin >> name;

if(name.size() > 4 && i

arr[i] = name;

}

fin.close();

sort_array(arr, arr_sz);

int mo = 0;

int ar = 0;

do

{ // fill smaller array

if(mo == 0 && ar == 0)

{ // index zero unique

mov[mo] = arr[ar];

mo++;

}

else if (is_unique(arr, arr_sz, ar))

{

mov[mo] = arr[ar];

mo++;

}

else

ar++;

} while (mo

}

void sort_array(string arr[],int sz)

{ // sorting array to alpha order

for (int i = 0; i

for (int j = i++; j

{

if (arr[i] > arr[j] && i

arr[i].swap(arr[j]);

}

}

bool is_unique(string arr[],int arr_sz, int idx)

{ // find a unique entry in the array

if (idx == 0 && idx

return true;

else if (arr[idx] != arr[idx - 1] && idx

return true;

else

return false;

}

void count_votes(string arr[], int sz,string mov[],int vts[], int vt_sz)

{ // count the repeats in the original array

int vt_ct = 0;

for (int mo = 0; mo

{

for (int ar = 0; ar

{

if (arr[ar] == mov[mo])

vt_ct++;

else

{ // write the vote to the vts array

vts[mo] = vt_ct;

vt_ct = 0;

}

}

}

}

void print_results(string mov[], int vts[], int sz)

{

int total = sum_votes(vts, sz);

cout

cout

cout

for (int i = 0; i

cout

cout

cout

}

int sum_votes(int vts[], int sz)

{ // total of all votes

int sum = 0;

for (int i = 0; i

sum = sum + vts[i];

return sum;

}

int win_idx(int vts[], int sz)

{ // movie with most votes

int idx = 0;

for (int i = 0; i

if (vts[i] > vts[idx])

idx = i;

return idx;

}

Unit 8: Programming CSIS 123 Programming Fundamentals: The purpose of this lab is to continue practicing concepts involving file I0, string operations, to reinforce using functions, and to reinforce control statements from previous chapters. Your file of media is here: user selections txt Your program should .Read from a file into an array of size 30 Sort the array alphabetically .Find the unique values in the original array and write to a string array of size 12 . Count the number of times a file is repeated in the larger array, write that value into a int array of size 12 Calculate the percentage of votes each movie earned Output the movies, votes, percentage, total, and winner to the screen . Use this as a starting pointunit 08_starting_ point.cpp Troubleshoot this code, find and identify the errors, submit the working version of this code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions