In: Computer Science
USING C#
1. Write a program that takes outputs a string, an integer and a floating-point number separated by commas. Sample output: Bob Marley, 20, 5.2 2.
2. Write a program that asks the user for a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’). Generate a random number of any size, integer or floating point, and combine those three pieces of information (in any order) to create a password and display that out to the user. Sample input 1: ILikePatterns + Sample output 1: 525235325ILikePatterns+ Sample input 2: ILikeDecimalNumbers / Sample output 2: ILikeDecimalNumbers/52325.25
1.
using System;
class MainClass {
public static void Main (string[] args) {
//Console.WriteLine ("Hello World");
String str;
int number;
float floatNumber;
Console.WriteLine("Enter a strting: ");
str=Console.ReadLine();
Console.WriteLine("Enter a number: ");
number=(int)Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a float number: ");
floatNumber=(float)Convert.ToDouble(Console.ReadLine());
Console.WriteLine(""+str+","+number+","+floatNumber);
}
}
==============
//Output
Enter a strting:
Bob Marley
Enter a number:
20
Enter a float number:
5.2
Bob Marley,20,5.2
=========================
2.
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine (" Enter a string of letters of any size (no spaces), and finally a special character (values 33 to 47 in the Ascii table, or ‘!’ to ‘/’): ");
string str="";
char c;
while(true)
{
c=(char) Console.Read();
if(c == 32) //if space don't take it
continue;
if(c>=33 && c<=47)
{
str+=c;
break;
}
str+=c;
}
Console.WriteLine ("\nString enetered is: "+str);
}
}
==========================
Enter a string of letters of any size (no spaces), and finally a
special character (values 33 to 47 in the Ascii table, or ‘!’ to
‘/’):
Hello WORLD!
String enetered is: HelloWORLD!
========================================
3.
using System;
public class Program {
public static void Main() {
Random rand = new Random();
int size= rand.Next(1,10);
Console.WriteLine("Enter a string: ");
string str=Console.ReadLine();
string str1="";
//generate integer number
for(int i = 0; i < size; i++)
str1+=rand.Next(0,10)+48;
string result=str+str1+"+";
Console.WriteLine(""+result);
}
}
=========================
//Output
Enter a string:
ILikeDecimalNumbers
ILikeDecimalNumbers48575149+