// Write a program which defines 2 integer constants and prints their sum, difference and //product.

Σχετικά έγγραφα
ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 11/3/2006

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 24/3/2007

Προγραμματισμός Υπολογιστών με C++

Η εντολή if-else. Η απλή μορφή της εντολής if είναι η ακόλουθη: if (συνθήκη) { Η γενική μορφή της εντολής ifelse. εντολή_1; εντολή_2;..

ΑΝΑΛΥΤΙΚΟ ΠΡΟΓΡΑΜΜΑ ΚΑΙ ΕΞΕΤΑΣΤΕΑ ΥΛΗ. ΔΟΜΗΜΕΝΟΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ Με τις Γλώσσες Προγραμματισμού Pascal, C, C++, Java

ιαδικτυακές Εφαρµογές

Αναφορές, είκτες και Αλφαριθμητικά

Φροντιςτήριο. Linked-List

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 19/5/2007

ΠΛΗΡΟΦΟΡΙΚΗ Ι JAVA Τμήμα θεωρίας με Α.Μ. σε 3, 7, 8 & 9 22/11/07

Στην ενότητα αυτή θα µελετηθούν τα εξής επιµέρους θέµατα: ΕΠΛ 131 Αρχές Προγραµµατισµού I 4-2

Γ7.2 Συμβολοσειρές (Strings) Γ Λυκείου Κατεύθυνσης

Αντικειμενοστρεφής Προγραμματισμός Διάλεξη 6 : ΠΙΝΑΚΕΣ

Δομή Επανάληψης. Κεφάλαιο 7 Mike Trimos

Προγραμματισμός Υπολογιστών με C++

Προγραμματισμός Ι. Πίνακες, Δείκτες, Αναφορές και Δυναμική Μνήμη. Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο

Προγραμματισμός Ι. Κλάσεις και Αντικείμενα. Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο

Συµβολοσειρές - Strings

Συναρτήσεις και Πίνακες

Πρόβλημα 1: Αναζήτηση Ελάχιστης/Μέγιστης Τιμής

Εντολές εισόδου - εξόδου. Εισαγωγή στη C++

ΠΛΗΡΟΦΟΡΙΚΗ Ι JAVA Τμήμα θεωρίας με Α.Μ. σε 3, 7, 8 & 9 25/10/07

ΠΛΗΡΟΦΟΡΙΚΗ Ι JAVA Τμήμα θεωρίας με Α.Μ. σε 3, 7, 8 & 9 1/11/07

Αρχεία & Ρεύματα ΑΡΧΕΙΑ & ΡΕΥΜΑΤΑ. Γεώργιος Παπαϊωάννου ( ) gepap@aueb.gr

Μονοδιάστατοι πίνακες

Προγραμματισμό για ΗΜΥ

Εισαγωγή στον Προγραµµατισµό. Διάλεξη 8 η : Συναρτήσεις Χειµερινό Εξάµηνο 2011

ΕΠΛ 032.3: Προγραµµατισµός ΜεθόδωνΕπίλυσηςΠροβληµάτων

ΒΑΣΙΚΟΙ ΤΥΠΟΙ ΚΑΙ ΠΙΝΑΚΕΣ

Διάλεξη 18η: Διαχείρηση Αρχείων

Γ7.1 Επανάληψη ύλης Β Λυκείου. Γ Λυκείου Κατεύθυνσης

Δισδιάστατοι Πίνακες (2D Arrays) Εισαγωγή στη C++

2 η Διάλεξη C++ Δρ. Χρήστος Δρόσος ΑΕΙ ΠΕΙΡΑΙΑ ΤΤ ΤΜΗΜΑ ΑΥΤΟΜΑΤΙΣΜΟΥ

ΤΕΧΝΙΚΕΣ ΑΝΤΙΚΕΙΜΕΝΟΣΤΡΑΦΟΥΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ. Πίνακες Κλάσεις και Αντικείμενα

Γλώσσα Προγραμματισμού C++ Εισαγωγή - Μια πρώτη ματιά

Το πρόγραμμα θα τυπώνει και τους τρεις πίνακες.

Προγραμματισμός Υπολογιστών με C++

Χωρική Βάση δεδοµένων Autocad

Εισαγωγή στον Αντικειμενοστρεφή Προγραμματισμό Διάλεξη #16

ιαφάνειες παρουσίασης #5

ΑΤΕΙ ΘΕΣΣΑΛΟΝΙΚΗΣ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ Αλγοριθμική και Προγραμματισμός. Παναγιώτης Σφέτσος.

Μαζέρας Αχιλλέας. Οι εντολές επανάληψης στην Pascal (While) Φυσικός Αυτοματιστής M.Sc. Νοέµβριος 2009

Προγραμματισμός PASCAL

(C) 2010 Pearson Education, Inc. All rights reserved.

Τεχνολογία και Προγραμματισμός Υπολογιστών. Η γλώσσα προγραμματισμού C

ΕΙΣΑΓΩΓΗ ΣΤΟΝ ΔΟΜΗΜΕΝΟ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟ

Χpήσιµες Βιβλιοθήκες της γλώσσας C

ΚΥΠΡΙΑΚΗ ΕΤΑΙΡΕΙΑ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ 6/5/2006

Δομημένος Προγραμματισμός (ΤΛ1006)

ΣΤΟΙΧΕΙΑ ΤΗΣ ΓΛΩΣΣΑΣ C++ Constructors, Destructors, Pointers IO Streams, File Streams

ΤΕΧΝΙΚΕΣ ΑΝΤΙΚΕΙΜΕΝΟΣΤΡΑΦΟΥΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ. Εισαγωγή στη Java III

Προγραμματισμός Ι. Εισαγωγή στην C++ Δημήτρης Μιχαήλ. Τμήμα Πληροφορικής και Τηλεματικής Χαροκόπειο Πανεπιστήμιο

ΠΛΗΡΟΦΟΡΙΚΗ Ι JAVA Τμήμα θεωρίας με Α.Μ. σε 3, 7, 8 & 9 29/11/07

ΛΥΣΕΙΣ ΘΕΜΑΤΩΝ ΤΕΛΙΚΗΣ ΦΑΣΗΣ Οι παρακάτω λύσεις είναι απολύτως ενδεικτικές

- Αναπαράσταση ακέραιας τιµής : - Εύρος ακεραίων : - Ακέραιοι τύποι: - Πράξεις µε ακεραίους (DIV - MOD)

Αντικειµενοστρεφής Προγραµµατισµός

ΚΛΑΣΕΙΣ ΜΕΘΟΔΟΙ - ΑΝΤΙΚΕΙΜΕΝΑ

17TimeThis.h function returns reference pointer to same object { return *this; }

Εισαγωγή στον Προγραμματισμό

Κεφάλαιο 2.6: Είσοδος / Έξοδος εδοµένων, Μορφοποίηση εδοµένων Εξόδου. ( ιάλεξη 7) ιδάσκων: ηµήτρης Ζεϊναλιπούρ

Αλγοριθμική & Δομές Δεδομένων- Γλώσσα Προγραμματισμού Ι (PASCAL)

Εισαγωγή στην πληροφορική

Μονοδιάστατοι πίνακες

Αντικειμενοστραφής Προγραμματισμός

Είσοδος και Έξοδος. (Input and Output) Διαφάνειες από τους Robert Sedgewick και Kevin Wayne. Τι θα δούµε σήµερα

Streams Input / Output in C++ George Kastrinis

ΤΕΧΝΙΚΕΣ ΑΝΤΙΚΕΙΜΕΝΟΣΤΡΑΦΟΥΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ. Εισαγωγή στη Java III

Κλήση Συναρτήσεων ΚΛΗΣΗ ΣΥΝΑΡΤΗΣΕΩΝ. Γεώργιος Παπαϊωάννου ( )

Π. Σταθοπούλου ή Οµάδα Α (Φοιτητές µε µονό αριθµό Μητρώου ) ιδασκαλία : Παρασκευή 11πµ-13µµ ΗΛ7

Εισαγωγή στον Προγραµµατισµό. Διάλεξη 2 η : Βασικές Έννοιες της γλώσσας προγραµµατισµού C Χειµερινό Εξάµηνο 2011

Επεξεργασία κειμένου και συμβολοσειρών σε C

Κεφάλαιο 2.6: Είσοδος / Έξοδος Δεδομένων, Μορφοποίηση Δεδομένων Εξόδου. (Διάλεξη 7) Είσοδος/ Έξοδος

Εισαγωγή στη JAVA. Εισαγωγή στη Java. Η Java είναι δημιούργημα της SUN MICROSYSTEMS.

ΤΕΧΝΙΚΕΣ ΑΝΤΙΚΕΙΜΕΝΟΣΤΡΑΦΟΥΣ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ. Πίνακες Κλάσεις και Αντικείμενα

1 ΕΙΣΑΓΩΓΗ. Πρωταρχικοί Τύποι

Κεφάλαιο 2.6: Είσοδος / Έξοδος Δεδομένων, Μορφοποίηση Δεδομένων Εξόδου. (Διάλεξη 7)

Προγραμματιστικές τεχνικές

ΚΥΠΡΙΑΚΟΣ ΣΥΝΔΕΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ CYPRUS COMPUTER SOCIETY 21 ος ΠΑΓΚΥΠΡΙΟΣ ΜΑΘΗΤΙΚΟΣ ΔΙΑΓΩΝΙΣΜΟΣ ΠΛΗΡΟΦΟΡΙΚΗΣ Δεύτερος Γύρος - 30 Μαρτίου 2011

Week 9: Input / Output

Προγραμματισμός Η/Υ Ι (Χρήση της C) 6 η Θεωρία ΜΟΝΟΔΙΑΣΤΑΤΟΙ ΠΙΝΑΚΕΣ

Συμβολοσειρές ΣΥΜΒΟΛΟΣΕΙΡΕΣ. Γεώργιος Παπαϊωάννου ( )

ΑΤΕΙ ΘΕΣΣΑΛΟΝΙΚΗΣ ΤΜΗΜΑ ΜΗΧΑΝΙΚΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ Αλγοριθμική και Προγραμματισμός. Παναγιώτης Σφέτσος

Προγραμματισμό για ΗΜΥ

ΠΡΟΤΥΠΑ. ΠΑΡΑ ΕΙΓΜΑ ηµιουργία πρότυπου στοίβας (stack) και στη συνέχεια δηµιουργία µιας στοίβας σηµείων.

ΕΛΛΗΝΙΚΗ ΕΤΑΙΡΕΙΑ ΕΠΙΣΤΗΜΟΝΩΝ ΚΑΙ ΕΠΑΓΓΕΛΜΑΤΙΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΩΝ ΜΕΛΟΣ IFIP, IOI

HY150a Φροντιστήριο 3 24/11/2017

Προγραμματισμός Υπολογιστών με C++

ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ Η/Υ Κανονική εξέταση, Φεβρουάριος 2005

ΕΙΣΟ ΟΣ-ΕΞΟ ΟΣ Ε ΟΜΕΝΩΝ

ΠΙΝΑΚΑΣ ΠΕΡΙΕΧΟΜΕΝΩΝ

Προγραμματισμός Η/Υ (ΤΛ2007 )

Τίτλος Μαθήματος: Ηλεκτρονικοί Υπολογιστές IΙΙ. Διδάσκων: Επίκουρος Καθηγητής Αθανάσιος Σταυρακούδης

Εργαστήριο 4_1 Λεκτική Ανάλυση - Flex Διδάσκοντες: Δρ. Γεώργιος Δημητρίου Δρ. Άχμεντ Μάχντι

Αντικείµενα. ηµιουργία και χρησιµοποίηση αντικειµένων. ηµιουργία αντικειµένων

Δομή Προγράμματος C++, Χειρισμός Μεταβλητών και Συναρτήσεις Εισόδου - Εξόδου

Εισαγωγή στη γλώσσα προγραμματισμού JAVA. Δομές Δεδομένων Διδάσκων: Π.Α. Μήτκας Τομέας Ηλεκτρονικής και Υπολογιστών

Προηγµένα Θέµατα Τεχνολογιών Υλοποίησης Αλγορίθµων

ΕΛΛΗΝΙΚΗ ΕΤΑΙΡΕΙΑ ΕΠΙΣΤΗΜΟΝΩΝ ΚΑΙ ΕΠΑΓΓΕΛΜΑΤΙΩΝ ΠΛΗΡΟΦΟΡΙΚΗΣ ΚΑΙ ΕΠΙΚΟΙΝΩΝΙΩΝ ΜΕΛΟΣ IFIP, IOI Org. GREEK COMPUTER SOCIETY MEMBER OF IFIP, IOI Org.

ΓΛΩΣΣΑ ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΥ PASCAL

Προγραμματισμός Ι (ΗΥ120)

Transcript:

Προγραμματισμού C++ // Write a program which defines 2 integer constants and prints their sum, difference and //product. //Να γραφεί πρόγραμμα το οποίο ορίζει δύο ακέραιες σταθερές και τυπών το άθροισμα, //τη διαφορά και το γινόμενο τους. #include <iostream> using namespace std; const int n1 = 5; const int n2 = 7; int sum = n1 + n2; int difference = n2 - n1; int product = n1 * n2; cout << "Sum = " << sum << endl; cout << "Difference = " << difference << endl; cout << "Product = " << product << endl; //Write a program which asks the user to input a string on the keyboard and then prints //the length of the string. //Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήση να εισάξει μια σειρά από //χαρακτήρες από το πληκτρολόγιο και τυπώνει το μέγεθος της. #include <iostream> #include <string> using namespace std; string line; // cin >> line; getline(cin,line); cout << "Length = " << line.length(); Δείγματα Ασκήσεων στη Σελίδα: 1/4 Copyright ECDL Cyprus 20011

Προγραμματισμού C++ // Write a program which asks the user to input 5 integers (one per line) and then prints //the sum of the integers which are even. // Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέραιους αριθμούς //(ένα σε κάθε γραμμή) και μετά τυπώνει το άθροισμα των ζυγών αριθμών. #include <iostream> using namespace std; int i,n,sum = 0; for (i=0; i<5; i++) cin >> n; if (n%2 == 0) sum = sum + n; cout << "Sum of even numbers = " << sum << endl; //Write a program which asks the user to input 5 integers (one per line), stores them in //an array, and then prints them in the reverse order in which they were input. // Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέριους αριθμούς //(ένα σε κάθε γραμμή), τους αποθηκεύει σε ένα πίνακα και μετά τους τυπώνει με την //αντίθετη σειρά από αυτή με την οποία εισήχθηκαν. #include <iostream> using namespace std; int i,n,a[5]; for (i=0; i<5; i++) cin >> n; a[i]=n; //print the numbers for (i=4;i>=0; i--) cout << a[i] << endl; Δείγματα Ασκήσεων στη Σελίδα: 2/4 Copyright ECDL Cyprus 20011

Προγραμματισμού C++ // Write a program which creates a compound data structure describing a box which has //4 fields (height,width,depth,colour) and outputs a line with the volume and colour of the //box. // Να γραφεί πρόγραμμα το οποίο δημιουργεί μία σύνθετη δομή δεδομένων η οποία //περιγράφει ένα κιβώτιο το οποίο έχει έχει 4 πεδία (ύψος, πλάτος, βάθος και χρώμα) και //τυπώνει μια γραμμή με τον όγκο και το χρώμα του κιβωτίου. #include <iostream> using namespace std; class Box public: float height,width,depth; string colour; ; Box thebox; thebox.height=5.5; thebox.width=3.3; thebox.depth=8.4; thebox.colour="blue"; cout << "This is a " << thebox.colour << " box with a volume of " << thebox.height * thebox.depth * thebox.width << endl; Δείγματα Ασκήσεων στη Σελίδα: 3/4 Copyright ECDL Cyprus 20011

Προγραμματισμού C++ // Write a program which reads a text file, converts it to lowercase, and then writes it to //another file. // Να γραφεί πρόγραμμα το οποίο διαβάζει ένα αρχείο κειμένου, το μετατρέπει σε μικρά //γράμματα και το γράφει σε ένα άλλο αρχείο κειμένου. #include <iostream> #include <fstream> #include <string> using namespace std; void tolowercase(string &str) const int length = str.length(); for(int i=0; i < length; ++i) str[i] = tolower(str[i]); ifstream infile; ofstream outfile; string line; infile.open("input.txt"); outfile.open("output.txt"); while (! infile.eof() ) getline (infile,line); tolowercase(line); outfile << line; infile.close(); outfile.close(); Σημείωση: Οι πιο πάνω λύσεις είναι ενδεικτικές και δεν έιναι μοναδικές. Δείγματα Ασκήσεων στη Σελίδα: 4/4 Copyright ECDL Cyprus 20011

Προγραμματισμού C // Write a program which defines 2 integer constants and prints their sum, difference and //product. //Να γραφεί πρόγραμμα το οποίο ορίζει δύο ακέραιες σταθερές και τυπών το άθροισμα, //τη διαφορά και το γινόμενο τους. #include <stdio.h> const int n1 = 5; const int n2 = 7; int sum = n1 + n2; int difference = n2 - n1; int product = n1 * n2; printf("sum = %d\n",sum); printf("difference = %d\n",difference); printf("product = %d\n",product); // This exercise is presented in four different solutions in order to show the variety of // options with the C Programming Language. // Αυτή η άσκηση παρουσιάζεται με τέσσερις διαφορετικές λύσεις για να δείξει την //ποικιλία των επιλογών στη. //Write a program which asks the user to input a string on the keyboard and then prints //the length of the string - Version 1. //Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήση να εισάξει μια σειρά από //χαρακτήρες από το πληκτρολόγιο και τυπώνει το μέγεθος της - Έκδοση 1. #include <stdio.h> #include <string.h> #define MAX 10000 char line[max]; gets(line); printf("length = %d\n",strlen(line)); Δείγματα Ασκήσεων στη Σελίδα: 1/6 Copyright ECDL Cyprus 2011

Προγραμματισμού C //Write a program which asks the user to input a string on the keyboard and then prints //the length of the string - Version 2. //Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήση να εισάξει μια σειρά από //χαρακτήρες από το πληκτρολόγιο και τυπώνει το μέγεθος της. - Έκδοση 2 #include <stdio.h> #include <string.h> #define MAX 10000 char line[max]; // scanf only inputs from first character to space or enter scanf("%s",line); printf("length = %d\n",strlen(line)); //Write a program which asks the user to input a string on the keyboard and then prints //the length of the string - Version 3. #include <stdio.h> #include <string.h> #define MAX 10000 char line[max]; char letter; int index=0; while ((letter=getchar())!='\n') line[index++]=letter; printf("length = %d\n",strlen(line)); printf("length = %d\n",index); Δείγματα Ασκήσεων στη Σελίδα: 2/6 Copyright ECDL Cyprus 2011

Προγραμματισμού C //Write a program which asks the user to input a string on the keyboard and then prints //the length of the string - Version 4. #include <stdio.h> #define MAX 10000 char line[max]; char letter; int index=0; while ((letter=getchar())!='\n') line[index++]=letter; printf("length = %d\n",index); // Write a program which asks the user to input 5 integers (one per line) and then prints //the sum of the integers which are even. // Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέραιους αριθμούς //(ένα σε κάθε γραμμή) και μετά τυπώνει το άθροισμα των ζυγών αριθμών. #include <stdio.h> int i,n,sum = 0; for (i=0; i<5; i++) scanf("%d",&n); if (n%2 == 0) sum = sum + n; printf("sum of even numbers = %d\n",sum); Δείγματα Ασκήσεων στη Σελίδα: 3/6 Copyright ECDL Cyprus 2011

Προγραμματισμού C //Write a program which asks the user to input 5 integers (one per line), stores them in //an array, and then prints them in the reverse order in which they were input. // Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέριους αριθμούς //(ένα σε κάθε γραμμή), τους αποθηκεύει σε ένα πίνακα και μετά τους τυπώνει με την //αντίθετη σειρά από αυτή με την οποία εισήχθηκαν. #include <stdio.h> int i,n,a[5]; for (i=0; i<5; i++) scanf("%d",&n); a[i]=n; //print the numbers for (i=4;i>=0; i--) printf("%d\n",a[i]); Δείγματα Ασκήσεων στη Σελίδα: 4/6 Copyright ECDL Cyprus 2011

Προγραμματισμού C // Write a program which creates a compound data structure describing a box which has //4 fields (height,width,depth,colour) and outputs a line with the volume and colour of the //box. // Να γραφεί πρόγραμμα το οποίο δημιουργεί μία σύνθετη δομή δεδομένων η οποία //περιγράφει ένα κιβώτιο το οποίο έχει έχει 4 πεδία (ύψος, πλάτος, βάθος και χρώμα) και //τυπώνει μια γραμμή με τον όγκο και το χρώμα του κιβωτίου. #include <stdio.h> typedef struct float height,width,depth; char colour[100]; box; box thebox; thebox.height=5.5; thebox.width=3.3; thebox.depth=8.4; printf("please enter a colour:"); scanf("%s", &thebox.colour); printf("this is a %s box with a volume of %f\n",thebox.colour, thebox.height * thebox.depth * thebox.width); Δείγματα Ασκήσεων στη Σελίδα: 5/6 Copyright ECDL Cyprus 2011

Προγραμματισμού C // Write a program which reads a text file, converts it to lowercase, and then writes it to //another file. // Να γραφεί πρόγραμμα το οποίο διαβάζει ένα αρχείο κειμένου, το μετατρέπει σε μικρά //γράμματα και το γράφει σε ένα άλλο αρχείο κειμένου. #include <stdio.h> #include <ctype.h> FILE *ifp, *ofp; int c; ifp = fopen("input.txt","r"); ofp = fopen("output.txt","w"); c = getc(ifp) ; while (c!= EOF) putchar(c); c = getc(ifp); putc(tolower(c),ofp); fclose(ofp); fclose(ifp); Σημείωση: Οι πιο πάνω λύσεις είναι ενδεικτικές και δεν έιναι μοναδικές. Δείγματα Ασκήσεων στη Σελίδα: 6/6 Copyright ECDL Cyprus 2011

Προγραμματισμού JAVA //Exercise 1 //Write a program which defines 2 integer constants and prints their sum, difference and //product. //Να γραφεί πρόγραμμα το οποίο ορίζει δύο ακέραιες σταθερές και τυπών το άθροισμα, //τη διαφορά και το γινόμενο τους. public class Exercise1 public static void main (String[] args) final int n1 = 5; final int n2 = 7; int sum = n1 + n2; int difference = n2 - n1; int product = n1*n2; System.out.println("Sum = " + sum); System.out.println("Difference = " + difference); System.out.println("Product = " + product); //Exercise 2 //Write a program which asks the user to input a string on the keyboard and then prints //the length of the string. //Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήση να εισάξει μια σειρά από //χαρακτήρες από το πληκτρολόγιο και τυπώνει το μέγεθος της. import java.io.bufferedreader; import java.io.inputstreamreader; public class Exercise2 public static void main(string[] args) throws Exception String inputline; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); inputline = input.readline(); System.out.println(inputLine.length()); Δείγματα Ασκήσεων στη Σελίδα: 1/5 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού JAVA

Προγραμματισμού JAVA //Exercise 3 //Write a program which asks the user to input 5 integers (one per line) and then prints //the sum of the integers which are even // Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέραιους αριθμούς //(ένα σε κάθε γραμμή) και μετά τυπώνει το άθροισμα των ζυγών αριθμών. import java.io.bufferedreader; import java.io.inputstreamreader; public class Exercise3 public static void main(string[] args) throws Exception int sum=0; for (int i=0; i<5; i++) String inputline; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); inputline = input.readline(); int n = Integer.parseInt(inputLine); if (n%2 == 0) sum=sum+n; System.out.println("Sum of even numbers = " + sum); Δείγματα Ασκήσεων στη Σελίδα: 2/5 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού JAVA

Προγραμματισμού JAVA //Exercise 4 //Write a program which asks the user to input 5 integers (one per line), stores them in //an array, and then prints them in the reverse order in which they were input // Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέριους αριθμούς //(ένα σε κάθε γραμμή), τους αποθηκεύει σε ένα πίνακα και μετά τους τυπώνει με την //αντίθετη σειρά από αυτή με την οποία εισήχθηκαν. import java.io.bufferedreader; import java.io.inputstreamreader; public class Exercise4 public static void main(string[] args) throws Exception int[] a = new int[5]; //read the numbers for (int i=0; i<5; i++) String inputline; BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); inputline = input.readline(); int n = Integer.parseInt(inputLine); a[i]=n; System.out.println(); //blank line //print the numbers for (int i=4; i>=0; i--) System.out.println(a[i]); Δείγματα Ασκήσεων στη Σελίδα: 3/5 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού JAVA

Προγραμματισμού JAVA //Exercise 5 //write a program which creates a compound data structure describing a box which has 4 //fields (height,width,depth,colour) and outputs a line with the volume and colour of the //box // Να γραφεί πρόγραμμα το οποίο δημιουργεί μία σύνθετη δομή δεδομένων η οποία //περιγράφει ένα κιβώτιο το οποίο έχει έχει 4 πεδία (ύψος, πλάτος, βάθος και χρώμα) και //τυπώνει μια γραμμή με τον όγκο και το χρώμα του κιβωτίου. public class Exercise5 static class Box public double height,width,depth; public String colour; public static void main(string[] args) Box thebox = new Box(); thebox.height=5.5; thebox.width=3.3; thebox.depth=8.4; thebox.colour="blue"; System.out.println("This is a " + thebox.colour + " box with a volume of " + thebox.height*thebox.depth*thebox.width); Δείγματα Ασκήσεων στη Σελίδα: 4/5 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού JAVA

Προγραμματισμού JAVA //Exercise 6 //write a program which reads a text file, converts it to lowercase, and then writes it to //another file // Να γραφεί πρόγραμμα το οποίο διαβάζει ένα αρχείο κειμένου, το μετατρέπει σε μικρά //γράμματα και το γράφει σε ένα άλλο αρχείο κειμένου. import java.io.bufferedreader; import java.io.bufferedwriter; import java.io.filewriter; import java.io.filereader; import java.io.writer; public class Exercise6 public static void main(string[] args) throws Exception String inputfile="input.txt"; String outputfile="output.txt"; BufferedReader input = new BufferedReader(new FileReader(inputFile)); BufferedWriter output = new BufferedWriter(new FileWriter(outputFile)); String line; while (( line = input.readline())!= null) output.write(line.tolowercase()); output.newline(); output.close(); Σημείωση: Οι πιο πάνω λύσεις είναι ενδεικτικές και δεν έιναι μοναδικές. Δείγματα Ασκήσεων στη Σελίδα: 5/5 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού JAVA

Προγραμματισμού PASCAL (* Write a program which defines 2 integer constants and prints their sum,difference, product *) (*Να γραφεί πρόγραμμα το οποίο ορίζει δύο ακέραιες σταθερές και τυπών το άθροισμα, τη διαφορά και το γινόμενο τους. *) PROGRAM Exercise1; CONST n1 : integer = 5; n2 : integer = 7; VAR sum, difference, product : integer; BEGIN sum := n1 + n2; difference := n2 - n1; product := n1 * n2; END. writeln ('Sum = ', sum); writeln ('Difference = ', difference); writeln ('Product = ', product); (* Write a program which asks the user to input a string on the keyboard and then prints the length of the string *) (*Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήση να εισάξει μια σειρά από χαρακτήρες από το πληκτρολόγιο και τυπώνει το μέγεθος της*). PROGRAM Exercise2; VAR inputline : String; BEGIN readln (inputline); writeln (Length(inputLine)); END. Δείγματα Ασκήσεων στη Σελίδα: 1/4 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού PASCAL

Προγραμματισμού PASCAL (* Write a program which asks the user to input 5 integers (one per line) and then prints the sum of the integers which are even *) (*Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέραιους αριθμούς (ένα σε κάθε γραμμή) και μετά τυπώνει το άθροισμα των ζυγών αριθμών. *) PROGRAM Exercise3; VAR sum : integer = 0; i : integer; inputnumber : integer; BEGIN for i := 1 to 5 do Begin readln(inputnumber); if ((inputnumber mod 2) = 0) then sum := sum + inputnumber; End; writeln ('Sum of even numbers = ', sum); END. (* Write a program which asks the user to input 5 integers (one per line), stores them in an array, and then prints them in the reverse order in which they were input *) (*Να γραφεί πρόγραμμα το οποίο ζητά από τον χρήστη να εισάξει 5 ακέριους αριθμούς (ένα σε κάθε γραμμή), τους αποθηκεύει σε ένα πίνακα και μετά τους τυπώνει με την αντίθετη σειρά από αυτή με την οποία εισήχθηκαν. *) PROGRAM Exercise4; VAR i : integer; inputnumber : integer; a : array[1..5] of integer; BEGIN for i := 1 to 5 do Begin readln(inputnumber); a[i] := inputnumber; End; Δείγματα Ασκήσεων στη Σελίδα: 2/4 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού PASCAL

Προγραμματισμού PASCAL END. writeln(); for i := 5 downto 1 do Begin writeln(a[i]); End; (* write a program which creates a compound data structure describing a box which has 4 fields (height,width,depth,colour) and outputs a line with the volume and colour of the box *) (* Να γραφεί πρόγραμμα το οποίο δημιουργεί μία σύνθετη δομή δεδομένων η οποία περιγράφει ένα κιβώτιο το οποίο έχει έχει 4 πεδία (ύψος, πλάτος, βάθος και χρώμα) και τυπώνει μια γραμμή με τον όγκο και το χρώμα του κιβωτίου. *) PROGRAM Exercise5; TYPE VAR Box = Record height, width, depth : real; colour : String; end; thebox : Box; BEGIN With thebox do Begin height := 5.5; width := 3.3; depth := 8.4; colour := 'blue'; End; writeln('this is a ', thebox.colour, ' box with a volume of ', thebox.height*thebox.depth*thebox.width:2:2); (* The ":2:2" is used to format the output data in a manner that is more understandable *) END. Δείγματα Ασκήσεων στη Σελίδα: 3/4 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού PASCAL

Προγραμματισμού PASCAL (* write a program which reads a text file, converts it to lowercase, and then writes it to another file *) (*Να γραφεί πρόγραμμα το οποίο διαβάζει ένα αρχείο κειμένου, το μετατρέπει σε μικρά γράμματα και το γράφει σε ένα άλλο αρχείο κειμένου. *) PROGRAM Exercise6; VAR line : String; inputfile, outputfile : text; BEGIN assign (inputfile, 'input.txt'); reset (inputfile); assign (outputfile, 'output.txt'); rewrite (outputfile); While not EOF(inputFile) do Begin readln (inputfile, line); writeln (outputfile, lowercase(line)); End; close(inputfile); close(outputfile) END. Σημείωση: Οι πιο πάνω λύσεις είναι ενδεικτικές και δεν έιναι μοναδικές. Δείγματα Ασκήσεων στη Σελίδα: 4/4 Copyright ECDL Cyprus 2011 Γλώσσα Προγραμματισμού PASCAL