Write a countdown program which prints numbers from 50 to 25

Write a countdown program which prints numbers from 50 to 25 on the screen using a for loop? output should look like.. 50 49 25 goodbye. Given the declarations struct Brand {string company: string model;}; struct DiskType {Brandlnfo brand; float capacity;}; DiskTypc myDisk; which of the following statements is valid? myDisk.capacity = 1.44; myDisk.Brandlnfo = \"Memorex\"; myDisk.brand = \"Memorex\"; a and c above

Solution

6) Program is in C++

#include <iostream>

using namespace std;

int main()

{

for(int count=50;count>=25;count--) // We want to print from 50 to 25

      {

           cout<<count<<endl; // Print the count and give a new line

      }

      // For loop will be terminated once count reaches to 24 hence we have to print \"goodbye\" after that

      cout<<\"goodbye\";

      // here we can give newline character as well if we want the cursor to point to newline after printing

      retunr 0; // return 0 to as return value for the main function

}

7) In this question we are given two structures ass below

Struct BrandInfo

{

String company;

String model;

}

and

Struct Disktype

{

Brandinfo brand;

float capacity;

}

Then DiskType myDisk; // myDisk variable of Structure DiskType is decclared

and myDisk has 1 variable which is a Brandinfo Structure and another variable is float

Now

A) myDisk.capacity = 1.44 [VALID]

explanation : It has assigned a float value 1.44 into the memory allocated for variable capacity within the memory block of DiskType structure hence it is perfectly fine.

B) myDisk.BrandInfo = \"memorex\" [INVALID]

explanation : myDisk structure has a variable \"brand\"of Structure type \"BrandInfo\" but in the current context it is trying to assign a value to a TYPE (here it is Structure Brandinfo) but not the variable and which is incorrect. Correct thing will be to assign a value to a variable not the Structure. And if the variable is a structure then one should assign the value per each component.

C) myDisk.brand = \"memorex\" [INVALID]

Explanation : This is a incorrect statement since here we are trying to assign a value to a variable \"brand\" of structure \"BrandInfo\" which in-tern has 2 components called company and model. So correct thing is to assign the value per each component of variable \"brand\" of structure type \"BrandInfo\"

D) [Invalid] based on above explanation

Please let me know if more explanation is needed.

 Write a countdown program which prints numbers from 50 to 25 on the screen using a for loop? output should look like.. 50 49 25 goodbye. Given the declarations
 Write a countdown program which prints numbers from 50 to 25 on the screen using a for loop? output should look like.. 50 49 25 goodbye. Given the declarations

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site