100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
The Body Mass Index Program and Matric Certificate Program, Compulsory assignments $10.53
Add to cart

Other

The Body Mass Index Program and Matric Certificate Program, Compulsory assignments

 6 views  0 purchase
  • Course
  • Institution

Assignments 2 and 3 in Mat1503 deal with vectors and determinants ,particularly helpful for engineering and computer science students who will apply these principles in real life through the design of efficient search engine algorithms (matrices and determinants ) and safer vehicles (vectors) ...

[Show more]

Preview 2 out of 11  pages

  • November 9, 2022
  • 11
  • 2022/2023
  • Other
  • Unknown
avatar-seller
Shivam_12596388_Assignment 2_uniqueCode_830369



Question 1 COS1511 Assignment 2: Writing Function headers in C++

Part (i): The function that returns no value from the caller
void check(int param1,float param2)
{
param1>param2;
param2=param1;
param2<param1;

}




Part (ii): The function that multiplies two values and returns the result:
void mult(float var1,float var2)
{
cout<<var1*var2;
}
int main()
{
mult(2,3);

return 0;

}




Part (iii): The function that tells you how many seconds, minutes and hours are in a day
void time(int seconds, int minutes,int hours)
{
cout<<"Within a day there are
"<<seconds<<"seconds,”<<minutes<<”minutes”<<hours<<”hours in a day
“<<endl<<endl;
}
int main()
{
time (60,60,24,);
return 0;
}

, Shivam_12596388_Assignment 2_uniqueCode_830369



Part (iv): The function that counts the amount of characters in a given string (phrase or sentence)

void countChar (string phraseofCharacters,int TotalCharacters)
{

phraseofCharacters="MonkeyBanana";

TotalCharacters=12;

cout<<"The phrase "<<phraseofCharacters<< " has "
<<TotalCharacters<< "Characters in the phrase
"<<phraseofCharacters<<endl<<endl<<endl;

}
int main ()
{
countChar( "MonkeyBanana",12 );

return 0;
}




Question 2 COS1511 Assignment 2: Debugging Errors in functions

Correcting errors in output code 2i

To call a function, simply do the following;
int main()
{
function1();

return 0;
}

Do not do the following in terms of calling functions

a) endl; int function2()

b) cout << "Inside function function1 " << endl;

Do the following to correct the above errors when calling functions in C++

• Always include the function you created within the main function within the default int
main () function.

• Never include endl;when ending functions , simply use the {} to end functions

• You cannot call a function without stating it in int main()

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller shivamnaik. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $10.53. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

50843 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$10.53
  • (0)
Add to cart
Added