Overclock.net banner

1 - 4 of 4 Posts

·
Registered
Joined
·
2,343 Posts
Discussion Starter · #1 ·
First of all this is the first program we have had to write by ourselves and it is working, but I don't think I did it the way he wanted to.

Below is information on what I was suppose to do:

-- Book instructions

1. Write an Ada program that will print your initials in large block letters, with each letter made up of the same character it represents. The letters should be a minimum of seven printed lines high and should appear in a row. For example, if your initials are DOW, your program should print out

112

Be sure to include appropriate comments in your program, choose meaning identifiers, and use indentation as we do in the programs in this chapter.

-- Teachers added instructions

Complete Programming Problem #1 on page 114 of your textbook. The obvious solution is to use string literals as actual parameters in seven calls to the procedure Ada.Text_IO.Put. An alternative (and easier) solution is to define seven named constants - one for each output line - and use those constants as actual parameters in seven calls to the procedure Ada.Text_IO.Put. Use this second alternative in your solution.

Call your program assign2 and store it in a file named assign2.adb Include header comments with your name and a brief description of what the program does.

Upload your program using the link below. Upload only the source code of your program.

Programs that do not compile will not be graded.

Here is the code for my program (disregard small things like the program is not named as he instructed and that I don't have seven lines in the text apperance, this was just a test.

Code:

Code:
with Ada.Text_IO;

procedure initials is

-- Constants
Line_one        : constant string :=  "RRRRR    JJJJJJJ  DDDD";
Line_two        : constant string :=  "R   R       J     D   D";
Line_three      : constant string :=  "RRRRR       J     D   D";
Line_four       : constant string :=  "R    R   J  J     D   D";
Line_five       : constant string :=  "R     R    J      D D";

begin

Ada.Text_IO.Put (Item => "RRRRR    JJJJJJJ  DDDD ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "R   R       J     D   D ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "RRRRR       J     D   D ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "R    R   J  J     D   D ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "R     R    J      D D ");

end initials;
As you may be able to see the constants are doing nothing at this point and the only thing displaying the letters are the Ada.Text_IO.Put commands. I am wondering if I did it the way he instructed or did I use the constants wrong.

Thanks for any and all help.

FYI, it may not look like the initials are aligned here, but they are in the program just fine. It looks like this in the program.

80
 

·
Registered
Joined
·
18 Posts
Quote:
Originally Posted by Bobicon View Post

First of all this is the first program we have had to write by ourselves and it is working, but I don't think I did it the way he wanted to.
Below is information on what I was suppose to do:
-- Book instructions
1. Write an Ada program that will print your initials in large block letters, with each letter made up of the same character it represents. The letters should be a minimum of seven printed lines high and should appear in a row. For example, if your initials are DOW, your program should print out
112
Be sure to include appropriate comments in your program, choose meaning identifiers, and use indentation as we do in the programs in this chapter.
-- Teachers added instructions
Complete Programming Problem #1 on page 114 of your textbook. The obvious solution is to use string literals as actual parameters in seven calls to the procedure Ada.Text_IO.Put. An alternative (and easier) solution is to define seven named constants - one for each output line - and use those constants as actual parameters in seven calls to the procedure Ada.Text_IO.Put. Use this second alternative in your solution.
Call your program assign2 and store it in a file named assign2.adb Include header comments with your name and a brief description of what the program does.
Upload your program using the link below. Upload only the source code of your program.
Programs that do not compile will not be graded.
Here is the code for my program (disregard small things like the program is not named as he instructed and that I don't have seven lines in the text apperance, this was just a test.

Code:

Code:
with Ada.Text_IO;
procedure initials is
-- Constants
Line_one        : constant string :=  "RRRRR    JJJJJJJ  DDDD";
Line_two        : constant string :=  "R   R       J     D   D";
Line_three      : constant string :=  "RRRRR       J     D   D";
Line_four       : constant string :=  "R    R   J  J     D   D";
Line_five       : constant string :=  "R     R    J      D D";
begin
Ada.Text_IO.Put (Item => "RRRRR    JJJJJJJ  DDDD ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "R   R       J     D   D ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "RRRRR       J     D   D ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "R    R   J  J     D   D ");
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (Item => "R     R    J      D D ");
end initials;
As you may be able to see the constants are doing nothing at this point and the only thing displaying the letters are the Ada.Text_IO.Put commands. I am wondering if I did it the way he instructed or did I use the constants wrong.
Thanks for any and all help.
FYI, it may not look like the initials are aligned here, but they are in the program just fine. It looks like this in the program.
80
I don't know ADA, but you're supposed to "use those constants as actual parameters in seven calls".
My guess would be something like Ada.Text_IO.Put (Line_one);
etc.
 

·
Registered
Joined
·
2,343 Posts
Discussion Starter · #3 ·
Quote:
Originally Posted by hangman View Post

I don't know ADA, but you're supposed to "use those constants as actual parameters in seven calls".
My guess would be something like Ada.Text_IO.Put (Line_one);
etc.
Yup, was that exactly.

Thanks for the help.
 

·
Registered
Joined
·
2,343 Posts
Discussion Starter · #4 ·
Program compiles and runs fine, but if anyone has any suggestions here is the final code I used for the project minus some comments explaining the program.

EDIT: The formatting for the strings on OCN appears wrong, but in the program it displays properly.

Code:

Code:
procedure assign2 is

-- Constants
line_one        : constant string := "RRRRR     JJJJJJJ DDDD";
line_two        : constant string := "R       R        J        D      D";
line_three      : constant string := "R       R        J        D       D";
line_four       : constant string := "RRRR          J        D       D";
line_five       : constant string := "R   R      J     J       D       D";
line_six        : constant string := "R    R     J    J        D      D";
line_seven      : constant string := "R     R     JJJ         DDDD";

begin
Ada.Text_IO.Put (line_one);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (line_two);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (line_three);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (line_four);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (line_five);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (line_six);
Ada.Text_IO.New_Line;
Ada.Text_IO.Put (line_seven);

end assign2;
 
1 - 4 of 4 Posts
Top