Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. // assessmentTask1.cpp : Defines the entry point for the console application.
  2. //Tylor Graham
  3. //558657
  4. //13/11/17
  5.  
  6. #include "stdafx.h"
  7. #include <iostream>
  8. #include <vector>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. unsigned short int vNoOfFiles = 0, vMaxFileSize = 0, vMaxFile = 0;
  14. vector<int> vecFileSize;
  15.  
  16. void getNoOfFiles(); //Declaring prototypes
  17. void getFileSize();
  18. void getMaxFile();
  19.  
  20.  
  21. int _tmain(int argc, _TCHAR* argv[])
  22. {
  23. getNoOfFiles(); //runs each procedure
  24. getFileSize();
  25. getMaxFile();
  26.  
  27. return 0;
  28. }
  29.  
  30. void getNoOfFiles(){
  31.  
  32. cout << "Please enter the number of files: " << endl; cin >> vNoOfFiles; //Asks the user to input how many files there is.
  33.  
  34. }
  35.  
  36. void getFileSize(){ //get the file sizes of all files.
  37.  
  38. for (int i = 0; i < vNoOfFiles; ++i){ //Repeat until we have sizes for each file.
  39.  
  40. int vTempSize = 0; //Placeholder variable
  41.  
  42. cout << "Please enter the file size (MB): " << endl; //Ask the user to enter the file size.
  43. cin >> vTempSize; //write the input to a placeholder.
  44.  
  45. vecFileSize.push_back(vTempSize); //using the placeholder, write the size to the vector vecFileSize.
  46.  
  47. }
  48.  
  49. }
  50.  
  51. void getMaxFile(){ //get the max file size.
  52.  
  53. vMaxFileSize = vecFileSize[0]; //Sets the vMaxFileSize to the first element
  54.  
  55. for (int i = 0; i < vNoOfFiles; ++i){ //Repeats for required amount of times
  56.  
  57. if (vecFileSize[i] > vMaxFileSize){ //If the vecFileSize is more than what is already the max
  58.  
  59. vMaxFileSize = vecFileSize[i]; //then change vMaxFileSize to studentHeight[i]
  60. vMaxFile = i;
  61.  
  62. }
  63.  
  64. }
  65.  
  66. cout << "The file number " << vMaxFile + 1 << " is the largest with a size of " << vMaxFileSize << "MB" << endl; //Output what file is the largest and what size it is.
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement