2/27/2011

DCT1063 Programming 2

ASSIGNMENT 2


 

  1. Explain the purpose of following function.


     

No 

Function

Purpose 

0 

strcpy 

Copies the string pointed by source into the array pointed by destination, including the terminating null character.

1 

strlen 

 

2 

strcmp 

 

3 

strcpy 

 

4 

strncpy 

 

5 

strcat 

 

6 

isalnum 

 

7 

islower 

 

8 

isspace 

 

9 

tolower 

 

10 

toupper 

 


 


 


 

  1. Write a program that reads one line of text and then prints it with all letters capitalized.


 

Input:        Abu Bakar

Output:    ABU BAKAR


 

3.     Write a program that separately inputs a first name and a last name and concatenates the two into a new string.


 

4. Write a program that reads one line of text and then prints the text in reverse order. For example, the input

today is tuesday

Would produce the output

yadseut si yadot


 

5.    Write a program that reads one line of text and then prints it with all its 'a','e', 'i', 'o', 'u','A','E', 'I', 'O', 'U' removed.

For example:

Input:        A structure (struct) type is a user defined composite type.

Output:    strctur (strct) typ is sr dfnd cmpsit typ.


 


 

6.     Write a program that counts the total number of vowels in a sentence. Output the frequency of each vowel.

For example:

Input:        A structure (struct) type is a user defined composite type.

Output:    A    :    2

        E    :    5

        I    :    3

        O    :    1

        U    :    4


 

7.    Write a program that reads one line of text and then prints the numbers of four-letter words that were read.


 

Input:        A structure (struct) type is a user defined composite type.

Output:    Number of words with four letter =3.


 


 


 


 

BCS1333 CPU Scheduling Exercise

Note Chapter 5 : CPU Scheduling Willey

TRUE/FALSE

  1. Process execution begins with a CPU burst. That is followed by an an I/O burst, which is followed by another CPU burst, then another I/O burst, and so on. [ T / F ]
  2. CPU scheduling is the task of selecting a waiting process from the ready queue and allocating the CPU to it.[ T / F ]
  3. The Final CPU burst ends with a system request to terminate execution.[ T / F ]
  4. The simplest CPU-scheduling algorithm is first-come, first-served.[ T / F ]
  5. Implementing Short Job First (SJF) scheduling is difficult because predicting the length of the next CPU burst is difficult.[ T / F ]
  6. Both priority and SJF scheduling may suffer from starvation.[ T / F ]
  7. Aging is the technique to prevent starvation.[ T / F ]
  8. Round-Robin (RR) is similar to FCFS except it has time quantum.[ T / F ]
  9. The average waiting time under the Round-Robin is often long.[ T / F ]
  10. THE FCFS algorithm is nonpreemptive; the RR is preemptive. [ T / F ]

SHORT ANSWER

  1. There a re five (5) criterion that have been suggested for comparing CPU scheduling algorithms. List and briefly explain each of them.

    ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

  2. Consider the following set of processes that arrive at time 0, with the length of the CPU burst given in miliseconds:


Process Burst Time Priority

P1 15 3

P2 10 1

P3 3 3

P4 5 2

The processes are assumed to have arrives in order P1,P2,P3,P4 all at time 0.

  1. Draw four Gantt ccharts that illustrate the execution of these processes using the following scheduling algorithms : FCFS, SJF, nonpreemptivr priority ( a smaller priority number implies a higher priority), and RR (quantum = 3).

    ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________


  2. What is the waiting time of each process of the scheduling algorithms in part a?

    ________________________________________________________________________________________________________________________________________________________________


  3. What is the turnaround time of each process of the scheduling algorithms in part a?

    ________________________________________________________________________________________________________________________________________________________________


  4. Which of the algorithms in part a results in the minimum average waiting time (over all processes)?

    ________________________________________________________________________________________________________________________________________________________________


  1. In priority scheduling, priorities can be defined either internally or externally. Briefly explain what is internal priorities and what is external priorities.

    ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________


  1. What is major problem with priority scheduling and what is the solution?

    ________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________



2/23/2011

BCT1113 CP lab 24/2/2011


Write a program that asks the user to type 10 integers and writes the sum of these integers. Use either while or do-while or for loop. Start with a pseudocode and flowchart.


Flowchart



C++ Program


#include<iostream.h>

int main(void)

{

int n;

int sum =0;

int counter = 1;

while(counter <=10)

{

cout<<"sila masukkan no ";

cin>>n;

sum = sum +n;

counter = counter +1;

}

cout<<"Hasil tambah 10 nombor ialah : "<<sum;

return 0;

}

2/19/2011

DCT1063 P2 PRE-TEST

A

The &
operator will returns the memory
address of its operand.

T/F

B 

The * operator
will returns the value of the variable located at the address specified by its operand.

T/F

C 

In C++, there is a close relationship between pointers and arrays.

T/F

D 

Consider the following fragment:

int no[3]={0,1,2};

int *p1;

p1 = no;

the statement no[1] or *(p1+1) will output the different result.

T/F

E 

Both statements (in D) will return the 1st element of array no .

T/F

F 

In order to perform file I/O, you must include the header <string.h>
in your program.

T/F

G 

To open an output stream, you must declare the stream to be of class ofstream.

T/F

H 

A stream that will be performing both input and output operations must be declared as class ifstream.

T/F

I 

The following fragment opens a file called out;

ofstream out;

out.open("test.txt");

T/F

J 

To close a file, use the member function close( ).

T/F


 

SECTION B –Show Output

1. What is output by the following program segment?


 

1 int number = 9;

2 int *p = &number; // address of number is 0010FF8C

3

4cout << number << " " << *p << " " << p;

(4 Marks)

answer


 


 


 


 


 

2. What is output by the following program segment?


 

1 int a[] = { 1, 3, 5, 7, 9 };

2 int *p = a;

3

4 cout << a[ 0 ] << " " << *( p + 1 ) << " " << p[ 2 ];

(4 Marks)


 

answer:


 


 


 


 

3. What is output by the following program segment?


 

1 int a[] = { 1, 2, 3, 4, 5 };

2 int *p = a;

3

4 cout << a[ 0 ];

5 cout << *(a+1);

6 cout << *(p + 2);

7 cout << p[ 3 ];

(5 Marks)


 

answer:


 


 


 


 


 


 


 


 

4. What is output by the following program segment?


 

1 int i,a[] = { 1, 2};// address of a[0] is 5000

2 int *p = a;

3

4 for(i=0;i<=1;i++)

5

6 cout << (p+i)<<" "<<*(p+i)<<endl;

(3 Marks)


 

answer


 


 


 

SECTION C –Programming



 

  1. Consider the following C++ program. Show the content of test.txt


    #include <iostream>

    #include <fstream>

    using namespace std;

    int main()

    {

    ofstream out("test.txt");

    out << 10 << " " << 123.23 << "\n";

    out << "This is a short text file.";

    out.close();

    return 0;

    }


 


 


 

2. Write a program that prompts user to enter:-


 

  1. Name
  2. Age
  3. State
  4. Country


 

and write into a file named biodata.txt as follows.


 

Name     : Ahmad Ashraaf

Age    : 19

State: terengganu

Country: Malaysia


 


 


 

(10 Marks)

2/12/2011

QUIZ 2 BCS1333

Chapter 4 : Threads


 

1. What is thread (in Operating Systems)? (3 marks)

2. The benefits of multithreaded programming can be broken down into four major categories. List all of them. (4 marks)

3. There are two level of threads; user thread and kernel thread. Briefly explain what is user thread and kernel thread. (4 marks)

4. Draw a figure to illustrate the three model of Multithreading (Many to one, one to one and many to many). (4 marks)


 

Click here to download chapter 4 lectures slide.

Due date 14 feb 2011. 830 am (during lab session).

Note: Solution for questions 1, 2, and 4 can be found on the given slide. Please google (search on internet) for question 3.

2/11/2011

ELAK SAMBUT VALENTINE’S DAY (MUSLIM)


"Dalam hal ini Panel Kajian Aqidah (PKA) dan Panel Kajian Syariah (PKS) Jabatan
Kemajuan Islam Malaysia (JAKIM) telah memutuskan bahawa “Amalan
menyambut Hari Valentine’s Day adalah haram dan bertentangan
dengan ajaran Islam”. Manakala Jawatankuasa Fatwa Majlis
Kebangsaan Bagi Hal Ehwal Agama Islam Malaysia kali ke-71 yang
bersidang pada 22 hingga 24 November 2005 memutuskan: “Bahawa
amalan merayakan Valentine’s Day tidak pernah dianjurkan oleh Islam.
Roh perayaan tersebut mempunyai unsur-unsur Kristian dan
amalannya yang bercampur dengan perbuatan maksiat adalah
bercanggah dan dilarang oleh Islam. Oleh itu amalan meraikan Hari
Kekasih tidak digalakkan oleh agama Islam”.

Untuk tulisan penuh - sila klik pada pautan ini.

2/10/2011

Cara padam/ganti file dalam system32


Dalam sesetengah keadaan (contohnya untuk crack software!), beberapa fail dalam folder C:\windows\system32 perlu di ganti secara manual. Biasanya ia melibatkan fail *.dll (dll ialah file yang diperlukan oleh lebih dari satu program dalam satu masa yang sama).

Dalam keadaan biasa-proses tersebut (padam/ganti fail) tidak dapat di lakukan kerana 'protection' daripada windows (terutamanya untuk vista dan windows 7).

Dua artikel berikut menerangkan satu kaedah mudah bagi melakukan perkara tersebut.

How To: Replace/Delete Protected DLL Files In Windows 7 & Vista

How To: Take Ownership Of A Folder/File In Windows 7

Cara download Installer windows 10 dalam format ISO

1. Jika anda bercadang untuk download windows 10 melalui website rasmi windows - pilihan untuk download dalam format ISO tidak di berikan.  ...