intro to C++ practice project. I would appreciate all help on this so that i may
ID: 3720989 • Letter: I
Question
intro to C++ practice project. I would appreciate all help on this so that i may study it for my exam
============================
This is the unsorted_media.txt: (https://pastebin.com/mnXXmnAy its a bit lengthy so i put it on pastebin) but if you dont want to go to paste bin, here are all of the format examples from the unsorted_media.txt
The whole thing is like 3000 long but here are examples all of the different formats used
============================
12_Years_a_Slave_(2013).mp4
13_Going_on_30_(2004).mkv
What's_Left_Of_Me_-_Bon_Jovi.mp3
130422_120414.jpg
2_Fast_2_Furious_(2003).m4v
20130424_125422.bmp
20130424_125427.gif
20130424_125445.tiff
20130424_125438.png
20130424_142647.jpg
21_Jump_Street.en.forced.srt
A_Christmas_Carol_-_George_C_Scott_(1984).avi
desktop.ini
desktop.ini
desktop.ini
Kill_the_Lights.wma
============================
And this is what it is supposed to look like: (the sample output)
Unit 7: Programming CSIS 123 Programming Fundamentals: The purpose of this lab is to practice some string operations, to reinforce using functions, and to reinforce control statements from previous chapters. The media server project is going well, however the volume of files exceeds what a person could reasonbly click through one at a time. To practice an automated task, your friend asks if it is possible to evaluate and sort thousands o f es H me w hou user interven on our friend would like o see ? repor1 hal dern ns rales tie number of f les o evaluate, and he end resu c un ln each repository Your file of media is here unsorted media txt Your program should: Display to the user the total number of media files in an unsorted text source .Determine by media file format which source destination to write the media file Display a report of each source text file name, and the tolal number of files in that source . The program should take no user intervention, however "Press any key to continueis allowed . The program should utilize a minimum of FOUR defined functions Constraints .Do not use any concepts beyond the current chapter, unless explicitly stated in the tasks below Hint: Each individual function should perform only one funcion . You may call a function trom within a function . You should use a string value to represent the file name, instead of hard-coding example string media "unsorted_media.bxt" file_input.open(media) Task 1: Setup Variables 1. Add "unsorted_media.txt", "movies.txt","music.txt", images.txt","error.txt" to the resource files folder 2. Use preprocessor directives to include input/output, file inputoutput, string variables, and manipulators 3. Declare string variables for each item in Task 1.1 4. Declare int variables to hold a count value for each ilern in Task 1. 5. Declare a single string variable to hold the current item from the input stream 6. Separate Task 1 from Task 2 by pressing ENTER on your keyboard. This provides a single line of whitespace in your codeExplanation / Answer
#include<iostream>
#include<fstream>
#include <string>
#include <cstddef>
#include<bits/stdc++.h>
#define FILE_PATH "C:/Users/temp-01968/Desktop/mnXXmnAy.txt"
#define UNSORTED_PATH "C:/Users/temp-01968/Desktop/UNSORTED_MEDIA.txt"
#define MOVIE_PATH "C:/Users/temp-01968/Desktop/MOVIE.txt"
#define MUSIC_PATH "C:/Users/temp-01968/Desktop/MUSIC.txt"
#define IMAGE_PATH "C:/Users/temp-01968/Desktop/IMAGE.txt"
#define ERROR_PATH "C:/Users/temp-01968/Desktop/ERROR.txt"
using namespace std;
/*function to get type of file i.e. extention of file*/
string gettype(string name)
{
string last;
size_t index = name.find_last_of(".");
last=name.substr(index+1);
return last;
}
/*function to count totla files */
int count_data()
{
ifstream in;
in.open(FILE_PATH);
char temp[100];
int count=0;
while(!(in.eof()))
{
in.getline(temp,100);
count++;
}
in.close();
return count;
}
/*function to display report*/
void display_report(int all_,int movie_,int music_,int image_,int error_)
{
cout<<" SOURCE Files"<<endl;
cout<<"unsorted_media.txt "<<all_<<endl;
cout<<"movies.txt "<<movie_<<endl;
cout<<"music.txt "<<music_<<endl;
cout<<"image.txt "<<image_<<endl;
cout<<"error.txt "<<error_<<endl;
}
/*functoin to sort data in specified files in the source file folder*/
void sort_data()
{
ifstream in;
in.open(FILE_PATH);
ofstream unsorted_out,mov_out,mus_out,img_out,err_out;
unsorted_out.open(UNSORTED_PATH);
mov_out.open(MOVIE_PATH);
mus_out.open(MUSIC_PATH);
img_out.open(IMAGE_PATH);
err_out.open(ERROR_PATH);
int unsorted=0,movie=0,image=0,music=0,error=0;
char temp[100];
string ext="";
while(!(in.eof()))
{
//get data line by line
in.getline(temp,100);
//call gettype(string) function to get ext of data file
ext=gettype(temp);
//transform ext to lower case
transform(ext.begin(),ext.end(),ext.begin(),::tolower);
//store every data file in UNSORTED.txt
unsorted_out<<temp<<endl;
unsorted++;
//if file is of movie type
if(ext=="avi"||ext=="mvk"||ext=="mp4"||ext=="mov"||ext=="wav"||ext=="wma")
{
//cout<<" in movies";
mov_out<<temp<<endl;
movie++;
}
//if file is of music type
else if(ext=="flac"||ext=="m4a"||ext=="mp3"||ext=="wav"||ext=="wma")
{
//cout<<" in music";
mus_out<<temp<<endl;
music++;
}
//if file is of image type
else if(ext=="bmp"||ext=="gif"||ext=="jpg"||ext=="png"||ext=="tiff")
{
//cout<<" in images";
img_out<<temp<<endl;
image++;
}
//if file is of error type
else
{
//cout<<" in errors";
err_out<<temp<<endl;
error++;
}
}
//close all files
in.close();
unsorted_out.close();
mov_out.close();
mus_out.close();
img_out.close();
err_out.close();
//call display function to display report
display_report(unsorted,movie,music,image,error);
}
//main function
int main()
{
cout<<" You Have "<<count_data()<<" Files To Sort";
sort_data();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.