Sunday, July 22, 2007

[Answer] Review Exercises #3

Copy and paste this code to answer the question on the www.dotnetstarter.blogspot.com


using System;
using System.Collections.Generic;
using System.Text;

namespace Problem_3
{
class Program
{
static void Main(string[] args)
{
string a, b, c, d;
int A, B, C, D;
Console.Write("Enter integer 1: ");
a = Console.ReadLine();
Console.Write("Enter integer 2: ");
b = Console.ReadLine();
Console.Write("Enter integer 3: ");
c = Console.ReadLine();
Console.Write("Enter integer 4: ");
d = Console.ReadLine();
Console.WriteLine("");

A=Int32.Parse(a);
B = Int32.Parse(b);
C = Int32.Parse(c);
D =Int32.Parse(d);

MathUtil Math = new MathUtil(A, B, C, D);
Console.WriteLine("Sum: "+Math.sum);
Console.WriteLine("Product: " + Math.multi);
Console.WriteLine("Difference: " + Math.diff);
Console.WriteLine("Qoutient: " + Math.qout);
Console.ReadLine();
}
}
public class MathUtil
{
#region "fields"
int num1;
int num2;
int num3;
int num4;
float P3, P4;
#endregion

#region "constructor"
public MathUtil(int num1,int num2,int num3,int num4)
{
this.num1 = num1;
this.num2 = num2;
this.num3 = num3;
this.num4 = num4;
this.P3 = num3;
this.P4 = num4;
}
#endregion
#region "R-only Propertys"
public int sum
{
get
{
return num1+num2+num3+num4;
}
}
public int multi
{
get
{
return num1 * num2 * num3 * num4;
}
}
public int diff
{
get
{
return num1 - num2;
}
}
public float qout
{
get
{

return P3 / P4;
}
}
#endregion
}
}


[Answer] Review Exercises # 1&2


using System;
using System.Collections.Generic;
using System.Text;

namespace Albores_Francis
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("------------------Problem 1------------------");
string a, b, c, d;
int sum, prod, diff, A, B, C, D;
float qout;
Console.Write("Enter integer 1: ");
a = Console.ReadLine();
Console.WriteLine("");
Console.Write("Enter integer 2: ");
b = Console.ReadLine();
Console.WriteLine("");
Console.Write("Enter integer 3: ");
c = Console.ReadLine();
Console.WriteLine("");
Console.Write("Enter integer 4: ");
d = Console.ReadLine();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("");
A = Int32.Parse(a);
B = Int32.Parse(b);
C = Int32.Parse(c);
D = Int32.Parse(d);
sum = A + B + C + D;
prod = A * B * C * D;
diff = A - B;
qout = 1/2;
Console.WriteLine("Sum: " + sum);
Console.WriteLine("");
Console.WriteLine("Product: " + prod);
Console.WriteLine("");
Console.WriteLine("Difference (1 and 2): " + diff);
Console.WriteLine("");
Console.WriteLine("Quotient (3 and 4): " + qout);
Console.WriteLine("");

Console.WriteLine("------------------Problem 2------------------");
string numofStud_S, grade_S, persentPS, persentFS;
int numofStud, grade, passed = 0, failed = 0;
float persentP, persentF;
Console.Write("Enter number of students to process: ");
numofStud_S = Console.ReadLine();
numofStud = Int32.Parse(numofStud_S);
bool invalid = false;
for (int x = 0; x < numofStud; x++)
{
do
{
Console.Write("Enter grade for student {0} 60-100: ", x + 1);
grade_S = Console.ReadLine();
grade = Int32.Parse(grade_S);
if (grade <> 100)
{
Console.WriteLine("Error: Grade must be within 60 to 100");
invalid = true;
}
else
invalid = false;
} while (invalid == true);
if (grade >= 75 && grade <= 100)
passed++;
else
{
failed++;
}
}
persentPS = passed.ToString();
persentFS = failed.ToString();
Console.WriteLine("");
Console.WriteLine("Total no. of students: "+numofStud);
Console.WriteLine("No. of students who passed: " + passed);
Console.WriteLine("No. of students who failed: " + failed);
Console.WriteLine("");
persentP = (float.Parse(persentPS) / float.Parse(numofStud_S) * 100);
persentF = (float.Parse(persentFS)/float.Parse(numofStud_S)*100);
Console.WriteLine("Percentage of students who passed: "+persentP+"%");
Console.WriteLine("Percentage of students who failed: " + persentF + "%");
Console.ReadLine();
}
} }

[Answer] Problem #3 EXAM dotnetstarter.blogspot.com

Copy and paste this code to answer the question. for the question, just click the title.


using System;
using System.Collections.Generic;
using System.Text;

namespace Exam01
{
class Program
{
static void Main(string[] args)
{
Book book1 = new Book();
book1.Type = BookType.Science;
book1.Pages = 150;
book1.Title = "Practical Science";
book1.Author = "Professor X1"; // Displays an error since the author name has a digit
Console.WriteLine(book1.Author); // Displays 'Unknown' since the author field is blank
book1.Author = "Professor X";
Console.WriteLine(book1); // Display's 'Type: Science, Title: Practical Science, Author: Professor X, Pages: 150'

Book book2 = new Book(BookType.History, "World History", "Magellan");

book2.Borrow(); // Sets the book status to borrowed
Console.WriteLine(book2.IsBorrowed); // Displays true
book2.Borrow(); // Displays an error since book is already borrowed

book2.Return(); // Sets the book status to available
Console.WriteLine(book2.IsBorrowed); // Displays false
book2.Return(); // Displays an error since book is already returned

Console.ReadLine();
}
}
public enum BookType
{
Undefined,
Fiction,
NonFiction,
History,
Science
}

public enum StatusType
{
Undefined,
Available,
Borrowed
}

public class Book
{
#region "fields"
private int _pages;
private string _title;
private string _author;
private BookType _bookType;
private StatusType _statusType;
#endregion
#region "Constructors"
public Book(BookType bookType, string title, string author, int pages)
{
_pages = pages;
_title = title;
_author = author;
_bookType = bookType;
_statusType = StatusType.Available;
}
public Book(BookType bookType, string title, string author)
{ }
public Book(string title,string author)
{ }
public Book()
{ }
#endregion
#region "Propertys"
public string Title
{
get{return _title;}
set{_title = value;}
}
public string Author
{
get
{
if (_author == "")
{
return "'Unknown' since the author field is blank";
}
else
return _author;
}
set
{
if (value.Contains("1") || value.Contains("2") || value.Contains("3") || value.Contains("4") || value.Contains("5") || value.Contains("6") || value.Contains("7") || value.Contains("8") || value.Contains("9") || value.Contains("0"))
{
Console.WriteLine("error since the author name has a digit");
_author = "";
}
else
_author = value;
}
}
public int Pages
{
get { return _pages; }
set { _pages = value; }
}
public BookType Type
{
get { return _bookType; }
set { _bookType = value; }
}
public bool IsBorrowed
{
get
{
if (_statusType == StatusType.Borrowed)
return true;
else
return false;
}
}

#endregion

#region "methods"
public void Borrow()
{
if (IsBorrowed == true)
Console.WriteLine("error since book is already borrowed");
else
_statusType = StatusType.Borrowed;
}
public void Return()
{
if(_statusType==StatusType.Available)
Console.WriteLine("error since book is already returned");
else
_statusType = StatusType.Available;
}
#endregion
public override string ToString()
{
return "Type: "+_bookType+", Title: "+_title+", Author: "+_author+", Pages: "+_pages;

}
}
}


[Answer]Problem #2 EXAM dotnetstarter.blogspot.com


using System;
using System.Collections.Generic;
using System.Text;
namespace practice
{
class Program
{
static void Main(string[] args)
{
string choice;
double C;
double a = 0.55555555555555555555555555555556;
double F;
bool repeat = false;
do
{
Console.WriteLine("Menu:");
Console.WriteLine("[C] Convert from Fahrenheit to Celsius");
Console.WriteLine("[F] Convert from Celsius to Fahrenheit");
Console.WriteLine("[X] Exit application");
Console.Write("Choice: "); repeat = false;
choice = Console.ReadLine();
switch (choice)
{
case "c":
case "C":
{
Console.Write("Enter temperature in Fahrenheit: ");
choice = Console.ReadLine();
if (choice == "")
{
repeat = true; break;
}
else
{
F = double.Parse(choice);
C = ((F - 32) * a);
Console.WriteLine("Temperature in Celcius: " + C);
repeat = true; break;
}
}
case "f":
case "F":
{
Console.Write("Enter temperature in Celsius: ");
choice = Console.ReadLine();
if (choice == "")
{
repeat = true; break;
}
else
{
C = double.Parse(choice);
F = (1.8) * C + 32;
Console.WriteLine("Temperature in Fahrenheit: " + F);
repeat = true; break;
}
}
case "x":
case "X":
{
Console.WriteLine("BABAY!!!"); break;
}
default:
{
Console.WriteLine("Error"); Console.ReadLine();
repeat = true; break;
}
}
} while (repeat == true);
}
}
}


ANSWER!!! Exam 1 UIC SysProg

This is a last year's post. I did just repost it because i forgot to publish it. It was just inside my draft. hahaha.....

using System;
using System.Collections.Generic;
using System.Text;
namespace practice
{
class Program
{
static void Main(string[] args)
{
string[] num = new string[3];
float[] numf = new float[3];
float index = 0;
int j;
for (int x = 0; x <>
{
Console.Write("Enter float {0}: ", x + 1);
num[x] = Console.ReadLine();
numf[x] = float.Parse(num[x]);
}
Console.WriteLine("");
Console.WriteLine("Order:");
for (int i = 0; i <>
{
index = numf[i];
j = i;
while ((j > 0) && (numf[j - 1] > index))
{
numf[j] = numf[j - 1];
j = j - 1;

}
numf[j] = index;

}
for (int x = 0; x <>
{
Console.WriteLine(numf[x]);
}
Console.ReadLine();
}
}
}

Answer Exam 1 UIC SysProg



using System;
using System.Collections.Generic;
using System.Text;
namespace practice
{
class Program
{
static void Main(string[] args)
{
string[] num = new string[3];
float[] numf = new float[3];
float index = 0;
int j;
for (int x = 0; x <>
{
Console.Write("Enter float {0}: ", x + 1);
num[x] = Console.ReadLine();
numf[x] = float.Parse(num[x]);
}
Console.WriteLine("");
Console.WriteLine("Order:");
for (int i = 0; i <>
{
index = numf[i];
j = i;
while ((j > 0) && (numf[j - 1] > index))
{
numf[j] = numf[j - 1];
j = j - 1;

}
numf[j] = index;
}
for (int x = 0; x <>
{
Console.WriteLine(numf[x]);
}
Console.ReadLine();
}
}
}