CSCI 150, Spring 2003

Home | | Course Schedule | | Assignments | | Lecture Notes

Lab 2 solution

Problem 1:

{program: shortWord.pas
Author: Brenda Student
Class: CSCI 150, Section 01
Date: 9/10/01
Assignment: lab 2
Purpose: Strips the first and last letter from a word.}

program shorten;
var
	word, shortWord: string;	{word entered and stripped word}
begin
	writeln('Please enter a word:');
	readln(word);
	shortWord := copy(word, 2, length(word) - 2);
	writeln('The stripped word is ', shortWord, '.');
end.

Problem 2:

{program: taxComp.pas
Author: Brenda Student
Class: CSCI 150, Section 01
Date: 9/10/01
Assignment: lab 2
Purpose: Computes tax deduction.}

program taxComp;
var
	answer: string;		{answer entered by user}
begin
	writeln('Are you married?');
	readln(answer);
	if answer = 'yes' then
	begin
		writeln('Are you filing jointly or separately?');
		readln(answer);
		if answer = 'separately' then
		begin
			writeln('Enter $1000 into line 7');
		end
		else
		begin
			writeln('Enter $2000 into line 7');
		end;
	end
	else
	begin
		writeln('Do you qualify as head of household?');
		readln(answer);
		if answer = 'yes' then
		begin
			writeln('Enter $2200 into lines 7 and 62');
		end
		else
		begin
			writeln('Enter $1000 into line 7');
		end;
	end;
end.