Question

In: Computer Science

3) Create a nested structure (one structure that contains another) and print out all the fields...

3) Create a nested structure (one structure that contains another) and print out all the fields in both structures. The main structure should have fields for: movie name and the year it was released. The extended structure should include the original structure as well as fields for: Lead actor, genre and runtime.

In C

4) Create a structure for an employee which contains a field for: first name, last name, id and salary. Then use printf and scanf to fill the structure. (Hint, you’ll have to use strcpy)

5) Make a counter using a for loop that counts from 0 to 200 in increments of 5.

6) Make a counter using a for loop that counts down from 200 to 0.

7) Create an array with 10 numbers, then print out each element plus the next element in the array. Note for the last element there will be no next element so there is no need to add to that element.

Solutions

Expert Solution

(a.)

#include<stdio.h>

#include<string.h>

/* FIRST STRUCTURE CONTAINS MOVIE NAME AND YEAR */

struct First
{
char mname[50];
int year;
};

/* STRUCTURE SECOND CONTAINS STRUCTURE FIRST VARIABLE, LEAD ACTOR, GENRE AND RUNTIME */

struct Second
{
struct First f1;
char lactor[50];
char genre[50];
int runtime;
};

int main(){

struct Second s1 = {"Avengers", 2019, "Tony Stark", "Fantasy", 120};

printf("%s %d %s %s %d", s1.f1.mname, s1.f1.year, s1.lactor, s1.genre, s1.runtime);

return 0;

}

(b.)

#include<stdio.h>

#include<string.h>

struct Employee{

char fname[50];

char lname[50];

int id;

int salary;

};

int main(){

char temp[50];

struct Employee e1;

/* TAKING EMPLOYEE DETAILS AS INPUT */

scanf("%s", &temp);

strcpy(e1.fname, temp);

scanf("%s", &temp);

strcpy(e1.lname, temp);

scanf("%d", &e1.id);

scanf("%d", &e1.salary);

/* PRINTING EMPLOYEE DETAILS AS OUTPUT */

printf("%s %s %d %d", e1.fname, e1.lname, e1.id, e1.salary);

return 0;

}

(c.)

#include<stdio.h>

int main(){

int counter=0;

for(counter=0; counter<=200; counter+=5){

printf("%d ", counter);

}

return 0;

}

(d.)

#include<stdio.h>

int main(){

int counter=0;

for(counter=200; counter>=0; counter-=5){

printf("%d ", counter);

}

return 0;

}

(e.)

#include<stdio.h>

int main(){

int a[10] = { 2, 5, 7, 9, 4, 6, 11, 10, 3, 8};

for(int i=0; i<10; i++){

if(i<9){

printf("%d ", a[i]+a[i+1]);}

else{

printf("%d", a[i]);

}

}

return 0;

}


Related Solutions

Create a structure array that contains the following information fields concerning the road bridges in a town
Create a structure array that contains the following information fields concerning the road bridges in a town: bridge location, maximum load (tons), year built, year due for maintenance. Then enter the following data into the array:
C++ In this lab you will be using nested for loops to print out stars in...
C++ In this lab you will be using nested for loops to print out stars in a Diamond pattern such as this: * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** * For example , if number of rows=8 then the above pattern is derived. You are to take the input for the number of lines(rows) from a file named "input_diamond" and output the pattern into both the terminal and an output file named "output_diamond".
JAVA Write nested while loop that will print out this pattern, based upon a number entered...
JAVA Write nested while loop that will print out this pattern, based upon a number entered by the user. User enters 4: 1234 1234 1234 1234 User enters 2: 12 12
in c#: Create a class named Square that contains fields for area and the length of...
in c#: Create a class named Square that contains fields for area and the length of a side and whose constructor requires a parameter for the length of one side of a Square. The constructor assigns its parameter to the length of the Square’s side field and calls a private method that computes the area field. Also include read-only properties to get a Square’s side and area. Create a class named DemoSquares that instantiates an array of ten Square objects...
CS 209 Data Structure 3. a. Create a class named Point3D that contains 3 instance variables...
CS 209 Data Structure 3. a. Create a class named Point3D that contains 3 instance variables x, y, and z. b. Create a constructor that sets the variables. Also, create get and set methods for each variable. c. Create a toString() method. d. Make Point3D implement Comparable. Also, create a compareTo(Point3D other) method that compares based on the x-coordinate, then y-coordinate for tiebreakers, then z-coordinate for tiebreakers. For example, (1, 2, 5) comes before (2, 1, 4), which comes before...
3- Ethics is one of the basics of working in all fields. How ethics play an...
3- Ethics is one of the basics of working in all fields. How ethics play an important role in work and education especially student ethics and how it is applied in distance education?
1.If one statement is nested within another statement, as in a loop or recursive call, what...
1.If one statement is nested within another statement, as in a loop or recursive call, what is the running time of the two statements when considered as a block? the running time for the inner statement added to the running time for the outer statement the running time for the inner statement multiplied by the running time for the outer statement the running time for the inner statement divided by the running time for the outer statement the running time...
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345...
Using Eclipse (Pyramid) Print out the following pyramid using nested loop. 1 12 123 1234 12345 1) the source code (.java file), and 2) the screenshot of running results of each question.
2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
Assume all 3 factors of 3-stage nested design are all random. What is the expected mean...
Assume all 3 factors of 3-stage nested design are all random. What is the expected mean square formula?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT