100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

COS1511- assignment 2 solutions with output 2023

Rating
-
Sold
-
Pages
18
Uploaded on
11-05-2023
Written in
2022/2023

This document contains the solutions to assignment 2 for COS With all the codes and comments in them, functions and outputs to every question

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
May 11, 2023
Number of pages
18
Written in
2022/2023
Type
Other
Person
Unknown

Subjects

Content preview

ASSIGNMENT 02 COS1511 2023
QUESTION 1a.
while(age>30||finalMark<65)

{

cout<<”Candidate not suitable.”<<endl;

cout<<”Enter age: “;

cin>>age;

cout<<”Enter final mark: “;

cin>>finalMark;

}



QUESTION 1b.
CODE OUTPUT
a. for(int i=1;i<=1;i++) *
cout<<”*”;
cout<<endl;
b. for(int i=2;i>=2;i++) Endless loop of *
cout<<”*”;
cout<<endl;
c. for(int i=1;i<=1;i--) Endless loop of *
cout<<”*”;
cout<<endl;
d. for(int i=12;i>=9;1--) ****
cout<<”*”;
cout<<endl;
e. for(int i=0;i<=5;i++) ******
cout<<”*”;
cout<<endl;
f. for(int i=1;i<=5;i++) Syntax error.
cout<<”*”; “i” is inaccessible after the for loop.
i=i+1;
cout<<endl;


QUESTION 1c.

,PROGRAM.
#include <iostream>

using namespace std;

int main()

{

int i=0;

while(i<=10)

{

if (i<5 && i!=2)

cout<<"X";

i++;

}

return 0;

}

Output.




QUESTION 1d.

, PROGRAM.
#include <iostream>

using namespace std;

const int LIMIT =10;

int main()

{



float counter;

//The declaration of variables can be on the same line separated by a comma.

int number, zeros, odds, evens;

//The counter variables are inirialised to assure that they don’t acquire an unknown initial value.

zeros=0;

odds=0;

evens=0;



cout<<"Please enter "<<LIMIT<<" integers, positive,negative or zeros."<<endl;

cout<<"The number you entered are "<<endl;

for(counter=1;counter<=LIMIT; counter++)

{

cin>>number;



switch(number%2) //The switch statement is working on a remainder and (%) is used.

{

case 0:

evens++;

if (number==0) //correcting the boolean operator for number is equal to zero…(==) not (=)

zeros++;

break;

Available practice questions

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
ThinkLab University of South Africa (Unisa)
Follow You need to be logged in order to follow users or courses
Sold
171
Member since
2 year
Number of followers
118
Documents
107
Last sold
1 month ago
ThinkLab Tutorials

A group of tutors that upload notes, exam elaborations, exam packs, assignment solutions and free packs. Unlock the door to academic excellence with our top-notch document uploads! It's meticulously prepared with foolproof solutions that guarantee your success. Trust in our reliable resources and conquer any challenge that comes your way. Don't settle for anything less than perfection in your studies. Our reliable document boasts 100% correct solutions, meticulously reviewed for your success. Say goodbye to uncertainty and hello to unwavering confidence! Giving the best services as the modules we are uploading are considered. If you have any questions, you're welcome to message us directly.

Read more Read less
3.9

19 reviews

5
7
4
5
3
6
2
1
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions