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

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".
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:
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?
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?
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
Python create a function tryhard and print out the dictionary as a string form. For example...
Python create a function tryhard and print out the dictionary as a string form. For example def tryhard(d:dict): #Code here input: d = {'first': {}, 'second': {'1': {'move'}, '0': {'move', 'slow'}}, 'third': {'1': {'stop'}}} output = " first movie: [ ]\n third movie: [('1', ['stop'])]\n second movie: [('0', ['slow', 'move']), ('1', ['move'])]\n"
JAVA: Create a circle that contains the following... Sample code to work from provided below. FIELDS:...
JAVA: Create a circle that contains the following... Sample code to work from provided below. FIELDS: a private double that holds the radius. CONSTRUCTORS a no argument constructor that sets the radius to zero a constructor that takes a single argument of type double which is the radius. METHODS a method called "getRadius" which returns the current radius a method called "setRadius" which takes a single parameter of type double containing the new radius a method called "getArea" which returns...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT