Google Answers Logo
View Question
 
Q: C++ Assignment (easier) ( Answered 5 out of 5 stars,   1 Comment )
Question  
Subject: C++ Assignment (easier)
Category: Computers > Programming
Asked by: willstein-ga
List Price: $5.00
Posted: 07 Dec 2003 13:10 PST
Expires: 06 Jan 2004 13:10 PST
Question ID: 284486
Please convert the following designs into C++ Program
One program per design. Design's are practically the same thing.


-----What's Needed:-----
The Program and the appended output for each design.
Append the output to the source program.
Verify that the output for each program agrees with the trace table
for it's exercise.



---Design---




Design 12.3

/* Data Declarations */
	a: INTEGER
	b: INTEGER
	f: INTEGER

/* Initializations */
	a = 10
	b = 15
	f = 6

	WHILE (f < a) DO
		b = b + 3
		f = f + 1
		PRINT 'f = ', f, 'a = ',a
	ENDWHILE

STOP 12.3





-----------





Design 12.4

/* Data Declarations */
	a: INTEGER
	b: INTEGER
	f: INTEGER

/* Initializations */
	a = 10
	b = 15
	f = 6

	WHILE (f < a) DO
		PRINT 'f = ', f, 'a = ',a
		b = b + 3
		f = f + 1
	ENDWHILE

STOP 12.4





----------





Design 12.5

/* Data Declarations */
	a: INTEGER
	b: INTEGER
	f: INTEGER

/* Initializations */
	a = 10
	b = 15
	f = 6

	WHILE (f < a) DO
		b = b + 3
		f = f + 1
	ENDWHILE
	PRINT 'f = ', f, 'a = ',a

STOP 12.5





----------





Design 12.6

/* Data Declarations */
	a: INTEGER
	b: INTEGER
	f: INTEGER

/* Initializations */
	a = 10
	b = 15
	f = 6

	WHILE (f <= 12) DO
		IF (a >=6) THEN
			b = b - 2
			a = a - 3
		ENDIF
		f = f + 1
	ENDWHILE
	PRINT 'a = ', a
	PRINT 'b = ', b
	PRINT 'f = ', f
	
STOP 12.6





-----------





Design 12.7

/* Data Declarations */
	a: INTEGER
	b: INTEGER
	f: INTEGER

/* Initializations */
	a = 10
	b = 15
	f = 6

	WHILE (f <= 12) DO
		IF (a >=6) THEN
			b = b - 2
			a = a - 3
		ELSE
			b = b + 5
		ENDIF
		f = f + 1
	ENDWHILE
	PRINT 'a = ', a
	PRINT 'b = ', b
	PRINT 'f = ', f
	
STOP 12.7





----------





Design 12.8

/* Data Declarations */
	a: INTEGER
	b: INTEGER
	f: INTEGER

/* Initializations */
	a = 10
	b = 15
	f = 6

	WHILE (f <= 12) DO
		IF (a >=6) THEN
			b = b - 2
			a = a - 3
		ELSE
			b = b + 5
			f = f + 1
		ENDIF
		f = f + 1
	ENDWHILE
	
	IF (b >= 20) THEN
		PRINT 'b >= 20'
	ELSE
		PRINT 'a = ', a
		PRINT 'b = ', b
		PRINT 'f = ', f
	ENDIF
	PRINT 'Hello'

STOP 12.8





-----------

Clarification of Question by willstein-ga on 07 Dec 2003 13:12 PST
**NEEDED TONIGHT
Answer  
Subject: Re: C++ Assignment (easier)
Answered By: endo-ga on 07 Dec 2003 13:41 PST
Rated:5 out of 5 stars
 
Hi,

Thank you for your question.

Here is the code you requested and the appended outputs.



12.3


#include <iostream.h>


void main()

{
	int a;
	int b;
	int f;

	a=10;
	b=15;
	f=6;

	while(f<a){
		b+=3;
		f++;
		cout<<"f = "<<f<<" a = "<<a<<" ";
	}
 
 
}


Output:

f = 7 a = 10 f = 8 a = 10 f = 9 a = 10 f = 10 a = 10 



12.4


#include <iostream.h>


void main()

{
	int a;
	int b;
	int f;

	a=10;
	b=15;
	f=6;

	while(f<a){
		cout<<"f = "<<f<<" a = "<<a<<" ";
		b+=3;
		f++;
		
	}
 
 
}


Output:
f = 6 a = 10 f = 7 a = 10 f = 8 a = 10 f = 9 a = 10 


12.5


#include <iostream.h>


void main()

{
	int a;
	int b;
	int f;

	a=10;
	b=15;
	f=6;

	while(f<a){
		b+=3;
		f++;
		}
	cout<<"f = "<<f<<" a = "<<a<<" ";
 
 
}


Output:

f = 10 a = 10 



12.6

#include <iostream.h>


void main()

{
	int a;
	int b;
	int f;

	a=10;
	b=15;
	f=6;

	while(f<=12){
		if(a>=6)
		{
			b-=2;
			a-=3;
		
		}
		f++;
		}
	cout<<"a = "<<a<<"\n";
	cout<<"b = "<<b<<"\n";
	cout<<"f = "<<f<<"\n";
 
 
}


Output:

a = 4
b = 11
f = 13


12.7

#include <iostream.h>


void main()

{
	int a;
	int b;
	int f;

	a=10;
	b=15;
	f=6;

	while(f<=12){
		if(a>=6)
		{
			b-=2;
			a-=3;
		
		}
		else
			b+=5;

		f++;
		}
	cout<<"a = "<<a<<"\n";
	cout<<"b = "<<b<<"\n";
        cout<<"f = "<<f<<"\n";
 
 
}


Output:

a = 4
b = 36
f = 13



12.8

#include <iostream.h>


void main()

{
  int a;
  int b;
  int f;

  a=10;
  b=15;
  f=6;

while(f<=12){
 
 if(a>=6)
 {
  b-=2;
  a-=3;
 }
 
 else
 {
  b+=5;
  f++;
 }

  f++;
}

 if(b>=20)
  cout<<"b >= 20 \n";

 else
 {
  cout<<"a = "<<a<<"\n";
  cout<<"b = "<<b<<"\n";
  cout<<"f = "<<f<<"\n";
 }

cout<<"Hello";
}


Output:

b >= 20 
Hello



I hope this answers your question, if you require any clarifications
or if something is unclear please do not hesitate to ask.

Thanks.
endo
willstein-ga rated this answer:5 out of 5 stars

Comments  
Subject: Re: C++ Assignment (easier)
From: endo-ga on 16 Dec 2003 12:00 PST
 
Thank you for the great rating.
Kind regards,
endo

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy