Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 13th, 2012  |  syntax: C#  |  size: 2.37 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. public class Movie//Array of Objects Movie
  5. {
  6.     public string moviename { get; set; }
  7.     public int CastSize { get; set; }
  8.     public string[] CastMembers { get; set; }
  9. }
  10. public class MovieData//creates class MovieData
  11. {
  12.     public int NumberOfMovies = 0;
  13.     public string UserInput;
  14.     int count = 0;
  15.     public void ManageData()//creates method ManageData which stores data in an array
  16.     {
  17.         string[] text = File.ReadAllLines(@"Document.txt");
  18.         while(count<text.Length)//This creates a method that counts how many movies in order to create proper sized Movie
  19.         {
  20.             int temp = 0;
  21.             count++;
  22.             temp = Convert.ToInt32(text[count].Trim());
  23.             count++;
  24.             count = temp + count;
  25.             NumberOfMovies++;
  26.         }
  27.         Movie[] film = new Movie[NumberOfMovies]; //creates new Movie
  28.         int OurFilm = 0;
  29.         int TextCounter = 0;
  30.         while(TextCounter<text.Length)//Stores the data using a while loop and text[TextCounter]
  31.         {
  32.             film[OurFilm] = new Movie();
  33.             film[OurFilm].moviename = Convert.ToString(text[TextCounter].Trim());
  34.             TextCounter++;
  35.             film[OurFilm].CastSize = Convert.ToInt32(text[TextCounter].Trim());
  36.             TextCounter++;
  37.             int castsize = film[OurFilm].CastSize;
  38.             film[OurFilm].CastMembers = new string[castsize];
  39.             for (int j = 0; j < film[OurFilm].CastMembers.Length; j++)//stores data in castmember array within the array
  40.             {
  41.                 film[OurFilm].CastMembers[j] = Convert.ToString(text[TextCounter].Trim());
  42.                 TextCounter++;
  43.             }
  44.             OurFilm++;
  45.         }
  46.         Console.WriteLine("To see the films your movie star has appeared in please enter his/her name: ");
  47.         UserInput = Convert.ToString(Console.ReadLine());
  48.         for(int o =0; o < film.Length; o++)//searches the Movie array
  49.         {
  50.             for(int p = 0; p <film[o].CastMembers.Length; p++)//searches the castmember array within array Movie
  51.             {
  52.                 if(UserInput == film[o].CastMembers[p])//if user input matches the cast member
  53.                 {
  54.                     Console.WriteLine("\nFilm: {0}",film[o].moviename);//print movie name
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }