SRMicro Info Systems Interview Question for Testing / Quality Assurances


Country: INDIA
Interview Type: Written Test




Comment hidden because of low score. Click to expand.
0
of 0 vote

It is a C# solution for the question


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FileHierarchy_Csharp
{
class Program
{
static void Main(string[] args)
{
string traverseDirectory ="..\\..\\..\\..\\";
string extension = ".txt";
string[] keyword = new string[] { "file", "value" };
string[] lines,elements;
char[] seperator = new Char[]{':','\n'};
int index = 0;
string currentDirectory = Directory.GetCurrentDirectory();
string filePath = traverseDirectory+"a.abc"+extension;
string fileName = null;
bool found = false;
if (File.Exists(filePath))
{

lines = File.ReadAllLines(filePath);

for(int i = 0 ; found==false && i<lines.Count();i++)
{
elements = lines[i].Split(seperator);

foreach (string element in elements)
{
if (element.ToString() == keyword[0])
{
index = element.IndexOf(element);
fileName = elements[index+1];
found = true;
break;
}
}
}

found = false;

if(fileName!=null)
{
if (File.Exists(traverseDirectory + fileName + extension))
{

lines = File.ReadAllLines(filePath);
elements = lines[0].Split(seperator);
for (int i = 0; found == false && i < lines.Count(); i++)
{
elements = lines[i].Split(seperator);
foreach (string element in elements)
{
if (element.ToString() == keyword[1])
{
index = element.IndexOf(element);
fileName = elements[index+1];
found = true;
break;
}
}
}
}
}
Console.WriteLine(fileName);
}
string s = Console.ReadLine();
}
}
}

- karthiga.m1988 February 22, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thank you for replay but I want Perl script

- gunturanilkumar007 February 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I didn't really understand the question. What do you mean by?

a.abc file contains
file:b.abc
value:4
file:c.abc
value:6 ....

>>read a.abc file and get the file name and check that file is exist or not if file is exit read the value and print ..
When a.abc is read, we get file b.abc and there's a value 4 associated..so we print 4 ?
And if that's the case, when we get c.abc (also with a.abc.. should the o/p be 6 or should the other file be opened, with d.abc and e.abc inside?

P.S: I think we can do with less confusing filenames.

- D September 10, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

you can try this:

my $file12 = "a.abc";
&fileDep($file12);

# generate the dependency order 
sub fileDep {
my $file = shift;
open(READ1,"<$file");
while(<READ1>) { 
chomp;
if ($_=~ /(.*\.abc)/ ) {
 if (-e $1) {
 print "found file $1 \n";
 &fileDep($1);
 } else {
 print " file $1  not found\n";
  return;
 }
} else {
print " no further dep\n";
 return;
}
}
close READ1;
}

- anushenoy May 14, 2016 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More