Tuesday, May 19, 2015
Thursday, May 14, 2015
Final Question: Structured Programming Language
|
|
Final Question: Structured Programming Language
UNITED INTERNATIONAL UNIVERSITY (UIU)
Dept. Of Electrical
& Electronic Engineering (EEE)
Exam: Final,
Trimester: Summer, Year: 2010
Course: CSI 121
(Sec – A,B,E), Title: Structured Programming Language
Marks: 60, Time: 2:00 Hour
|
There are 6 questions. Answer any five. Figures in the
right-hand margin indicate full marks.
|
1.
|
|
Write the output of the program below:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
void main()
{
int i;
char str[40] =
{‘1’, ‘2’, ‘#’ , ‘ ’, ‘a’, ‘b’, ‘C’, ‘\0’ };
for( i=0; str[i];
i++ ){
if(isalpha(str[i])){
if(isupper(str[i])) printf( "A");
else printf( "A");
}
else
if(isdigit(str[i])) printf( "D");
else
if(isspace(str[i])) printf( "_");
else printf(
"O");
}
char s1[]=
“I am X ”;
char
s3[20], s2[]= “connected”;
strcpy(s3,
s1);
printf(“\n%s”,s3);
strcat(s3,
s2);
printf(“\n%s”,s3);
strcpy(&s3[5],
s2);
printf(“\n%s”,s3);
strcat(s3,
&s1[5]);
printf(“\n%s”,s3);
}
|
[12]
|
|
|
|
|
|
|
2.
|
|
Write the output of the program below:
#include <stdio.h>
#define SIZE 3
struct student {
int id;
char *name;
} student_list[SIZE];
int end = -1;
void insert( int, char* );
struct student remove();
void main( void )
{
insert( 21071063, "Zahid Hasan" );
insert( 21073010, "Md. Yaqub" );
insert( 21062076, "Nayan Rahman" );
insert( 21071003, "Amina Akhter" );
struct student tmp = remove(); printf( "%d
%s\n", tmp.id, tmp.name );
insert( 21091153, "Mukit-ul Hasan" );
tmp = remove(); printf( "%d %s\n", tmp.id,
tmp.name );
tmp = remove(); printf( "%d %s\n", tmp.id,
tmp.name );
tmp = remove(); printf( "%d %s\n", tmp.id,
tmp.name );
tmp = remove();
}
void insert( int id, char *name
)
{
if( end + 1 < SIZE ) {
end++;
for( int i=end; i>0; i-- )
student_list[i] =
student_list[i-1];
struct student tmp = { id, name };
student_list[0]
= tmp;
}
else
printf( "List is full\n" );
}
struct student remove()
{
if( end >= 0 ) {
struct student tmp = student_list[0];
for( int i=0; i<end; i++ )
student_list[i] =
student_list[i+1];
end--;
return tmp;
}
else
printf( "List is empty\n" );
}
|
[12]
|
|
|
|
|
|
|
3.
|
|
All the questions below are
part of a single program.
|
|
|
|
a.
|
Define a structure student_info that has two members: id and name where id is an
int and name is a string.
|
[2]
|
|
|
b.
|
Declare array variable students containing 10 student_info structures.
|
[2]
|
|
|
c.
|
Initialize students so that id of
1st entry is 0, id of 2nd
entry is 1 and so forth and, name
of 1st entry is name0, name
of 2nd entry is name1 and so forth.
|
[2]
|
|
|
d.
|
Open a file and write all the
information in students into the
file using fwrite() function. Make
sure to close the file.
|
[3]
|
|
|
e.
|
Open the file again and read
the info of the 5th student (i.e. student whose id is 4) from the file using fseek()
and fread() functions and print it on the screen. Make sure to close the file.
|
[3]
|
|
|
|
|
|
|
4.
|
|
Write a C program that reads a paragraph of text from
user and then prints the lines separately. Use a function to count and show
the number of words in each line.
|
[12]
|
|
|
|
|
|
|
5.
|
a.
|
Write a C program to read texts
from the keyboard and save them into a text file.
|
[6]
|
|
|
b.
|
Write a C program to read the
contents of a text file and print them on the screen.
|
[6]
|
|
|
|
|
|
|
6.
|
|
![]()
Write a program to get
information of 20 students from user and store them in an array of structures
defined above. Information includes grades and credit hours of three courses
they have taken this semester. The
program should calculate the GPA using following formula.
The program should then write GPA
information into “stdInfo.txt” using the following format.
![]() |
[12]
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
7.
|
|
Bonus: (Total may not exceed 60)
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
Three class test marks of 30
students are stored in “marks.txt” with the following format.
(format of the file marks.txt)
![]()
Write a program to read the
information from “data1.txt”. The program should then calculate and show the
average class test with the following format.
(format of the
output)
![]()
There are 6 questions. Answer any 5. Figures in the
right-hand margin indicate full marks.
There are 5 questions. Answer any 4. Figures in the
right-hand margin indicate full marks.
|
[12]
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Subscribe to:
Comments (Atom)






