LAB 1 - PROGRAMMING
1. Student Information
You will be given 3 lines of input – student name, age and average grade. Your task is to print all the
info about the student in the following format: "Name: {student name}, Age: {student age}, Grade:
{student grade}".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1_1
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Input Name: ");
string name = Console.ReadLine();
Console.Write("Input Age: ");
int age = int.Parse(Console.ReadLine());
Console.Write("Input Grade: ");
double grade = double.Parse(Console.ReadLine());
Console.WriteLine("Name: {0}, Age: {1}, Grade: {2}", name, age, grade);
Console.ReadKey();
}
}
}
2. Passed or Failed
Write a program, which takes as an input a grade and prints “Passed!” if the grade is equal or more
than 3.00.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1_2
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Input Grade: ");
double grade = double.Parse(Console.ReadLine());
if (grade >= 3 && grade < 10)
{
Console.WriteLine("Passed");
}
else
{
Console.WriteLine("Falsed");
}
Console.ReadKey();
}
}
}
3. Back in 30 Minutes
Every time Stamat tries to pay his bills he sees on the cash desk the sign: "I will be back in 30 minutes".
One day Stamat was sick of waiting and decided he needs a program, which prints the time after 30
minutes. That way he won’t have to wait on the desk and come at the appropriate time. He gave the
assignment to you, so you have to do it.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1_3
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Input Hours: ");
int h = int.Parse(Console.ReadLine());
Console.Write("Input Minutes: ");
int m = int.Parse(Console.ReadLine());
m = m + 30;
if (m >= 60)
{
h += 1;
m -= 60;
}
if (h >= 24)
{
h -= 24;
}
Console.Write("You can be back in: ");
Console.WriteLine($"{h:D2} | {m:D2}");
Console.ReadKey();
}
}
}
4. Month Printer
Write a program, which takes an integer from the console and prints the corresponding month. If the
number is more than 12 or less than 1 print "Error!".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1_4
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Input Month: ");
int month = int.Parse(Console.ReadLine());
switch (month)
{
case 1:
Console.WriteLine("Jan");
break;
case 2:
Console.WriteLine("Feb");
break;
case 3:
Console.WriteLine("Mar");
break;
case 4:
Console.WriteLine("Apr");
break;
case 5:
Console.WriteLine("May");
break;
case 6:
Console.WriteLine("Jun");
break;
case 7:
Console.WriteLine("Jul");
break;
case 8:
Console.WriteLine("Aug");
break;
case 9:
Console.WriteLine("Sep");
break;
case 10:
Console.WriteLine("Oct");
break;
case 11:
Console.WriteLine("Nov");
break;
case 12:
Console.WriteLine("Dec");
break;
default: Console.WriteLine("Error!");
break;
}
Console.ReadKey();
}
}
}
5. Foreign Languages
Write a program, which prints the language, that a given country speaks. You can receive only the
following combinations: English is spoken in England and USA; Spanish is spoken in Spain, Argentina
and Mexico; for the others, we should print "unknown".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1._5
{
internal class Program
{
static void Main(string[] args)
{
string country = Console.ReadLine();
switch (country.ToLower())
{
case "england":
case "usa":
Console.WriteLine("England");
break;
case "spain":
case "argentina":
case "mexico":
Console.WriteLine("Spainish");
break;
default: Console.WriteLine("unknown");
break;
}
Console.ReadKey();
}
}
}
6. Theatre Promotions
A theatre is doing a ticket sale, but they need a program to calculate the price of a single ticket. If the
given age does not fit one of the categories, you should print "Error!". You can see the prices in the
table below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab1_7
{
internal class Program
{
static void Main(string[] args)
{
Console.Write("Input age: ");
int age = Convert.ToInt32(Console.ReadLine());
Console.Write("Input type of Day: ");
string typeOfDay = Console.ReadLine();
if (age <= 18 && age >= 0)
{
switch (typeOfDay.ToLower())
{
case "weekday":
Console.WriteLine("Price of Ticket is 12$");
break;
case "weekend":
Console.WriteLine("Price of Ticket is 15$");
break;
case "holiday":
Console.WriteLine("Price of Ticket is 5$");
break;
default:
Console.WriteLine("Error!");
break;
}
}
else if (age <= 64 && age > 18)
{
switch (typeOfDay.ToLower())
{
case "weekday":
Console.WriteLine("Price of Ticket is 18$");
break;
case "weekend":
Console.WriteLine("Price of Ticket is 20$");
break;
case "holiday":
Console.WriteLine("Price of Ticket is 12$");
break;
default:
Console.WriteLine("Error!");
break;
}
}
else if (age <= 122 && age > 64)
{
switch (typeOfDay.ToLower())
{
case "weekday":
Console.WriteLine("Price of Ticket is 12$");
break;
case "weekend":
Console.WriteLine("Price of Ticket is 15$");
break;
case "holiday":
Console.WriteLine("Price of Ticket is 10$");
break;
default:
Console.WriteLine("Error!");
break;
}
}
else
{
Console.WriteLine("Error!");
}
Console.ReadKey();
}
}
}