using System;
using System.IO;
using System.Text;
public class Movie//Array of Objects Movie
{
public string moviename { get; set; }
public int CastSize { get; set; }
public string[] CastMembers { get; set; }
}
public class MovieData//creates class MovieData
{
public int NumberOfMovies = 0;
public string UserInput;
int count = 0;
public void ManageData()//creates method ManageData which stores data in an array
{
string[] text = File.ReadAllLines(@"Document.txt");
while(count<text.Length)//This creates a method that counts how many movies in order to create proper sized Movie
{
int temp = 0;
count++;
temp = Convert.ToInt32(text[count].Trim());
count++;
count = temp + count;
NumberOfMovies++;
}
Movie[] film = new Movie[NumberOfMovies]; //creates new Movie
int OurFilm = 0;
int TextCounter = 0;
while(TextCounter<text.Length)//Stores the data using a while loop and text[TextCounter]
{
film[OurFilm] = new Movie();
film[OurFilm].moviename = Convert.ToString(text[TextCounter].Trim());
TextCounter++;
film[OurFilm].CastSize = Convert.ToInt32(text[TextCounter].Trim());
TextCounter++;
int castsize = film[OurFilm].CastSize;
film[OurFilm].CastMembers = new string[castsize];
for (int j = 0; j < film[OurFilm].CastMembers.Length; j++)//stores data in castmember array within the array
{
film[OurFilm].CastMembers[j] = Convert.ToString(text[TextCounter].Trim());
TextCounter++;
}
OurFilm++;
}
Console.WriteLine("To see the films your movie star has appeared in please enter his/her name: ");
UserInput = Convert.ToString(Console.ReadLine());
for(int o =0; o < film.Length; o++)//searches the Movie array
{
for(int p = 0; p <film[o].CastMembers.Length; p++)//searches the castmember array within array Movie
{
if(UserInput == film[o].CastMembers[p])//if user input matches the cast member
{
Console.WriteLine("\nFilm: {0}",film[o].moviename);//print movie name
}
}
}
}
}