2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
15
Task/User-input-Text/Ada/user-input-text-3.ada
Normal file
15
Task/User-input-Text/Ada/user-input-text-3.ada
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
with Ada.Text_IO, Ada.Integer_Text_IO;
|
||||
|
||||
procedure User_Input is
|
||||
I : Integer;
|
||||
begin
|
||||
Ada.Text_IO.Put ("Enter a string: ");
|
||||
declare
|
||||
S : String := Ada.Text_IO.Get_Line;
|
||||
begin
|
||||
Ada.Text_IO.Put_Line (S);
|
||||
end;
|
||||
Ada.Text_IO.Put ("Enter an integer: ");
|
||||
Ada.Integer_Text_IO.Get(I);
|
||||
Ada.Text_IO.Put_Line (Integer'Image(I));
|
||||
end User_Input;
|
||||
18
Task/User-input-Text/Ada/user-input-text-4.ada
Normal file
18
Task/User-input-Text/Ada/user-input-text-4.ada
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
with
|
||||
Ada.Text_IO,
|
||||
Ada.Integer_Text_IO,
|
||||
Ada.Strings.Unbounded,
|
||||
Ada.Text_IO.Unbounded_IO;
|
||||
|
||||
procedure User_Input2 is
|
||||
S : Ada.Strings.Unbounded.Unbounded_String;
|
||||
I : Integer;
|
||||
begin
|
||||
Ada.Text_IO.Put("Enter a string: ");
|
||||
S := Ada.Strings.Unbounded.To_Unbounded_String(Ada.Text_IO.Get_Line);
|
||||
Ada.Text_IO.Put_Line(Ada.Strings.Unbounded.To_String(S));
|
||||
Ada.Text_IO.Unbounded_IO.Put_Line(S);
|
||||
Ada.Text_IO.Put("Enter an integer: ");
|
||||
Ada.Integer_Text_IO.Get(I);
|
||||
Ada.Text_IO.Put_Line(Integer'Image(I));
|
||||
end User_Input2;
|
||||
8
Task/User-input-Text/Elena/user-input-text.elena
Normal file
8
Task/User-input-Text/Elena/user-input-text.elena
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#import system.
|
||||
#import extensions.
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var num := console write:"Enter an integer: " readLine:(Integer new).
|
||||
#var word := console write:"Enter a String: " readLine.
|
||||
].
|
||||
2
Task/User-input-Text/Maple/user-input-text.maple
Normal file
2
Task/User-input-Text/Maple/user-input-text.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
printf("String:"); string_value := readline();
|
||||
printf("Integer: "); int_value := parse(readline());
|
||||
32
Task/User-input-Text/Rust/user-input-text.rust
Normal file
32
Task/User-input-Text/Rust/user-input-text.rust
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
use std::io::{self, Write};
|
||||
use std::fmt::Display;
|
||||
use std::process;
|
||||
|
||||
fn main() {
|
||||
let s = grab_input("Give me a string")
|
||||
.unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)));
|
||||
|
||||
println!("You entered: {}", s.trim());
|
||||
|
||||
let n: i32 = grab_input("Give me an integer")
|
||||
.unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap_or_else(|e| exit_err(&e, 2));
|
||||
|
||||
println!("You entered: {}", n);
|
||||
}
|
||||
|
||||
fn grab_input(msg: &str) -> io::Result<String> {
|
||||
let mut buf = String::new();
|
||||
print!("{}: ", msg);
|
||||
try!(io::stdout().flush());
|
||||
|
||||
try!(io::stdin().read_line(&mut buf));
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn exit_err<T: Display>(msg: T, code: i32) -> ! {
|
||||
let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
|
||||
process::exit(code)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue